473,394 Members | 2,031 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Init Control when dropped on form??

Hello all,

I have a control i wrote which inherits from asp:label. It worked fine. It
extends asp:label with a "For" property which implements the "for" attribute
of an html label tag (yes i know the latest framework vers. added this, but
i want ot get mine right as a learning exp.).

I added a designer class which turns the For property into a dropdown list
of the names of all the controls so you can simply pick one. When i added
the designer, the control no longer properly initialized its Text property
when you drop it on a webform. I THINK the problem is in then designer's
Initialize sub.

The code for my designer is shown below.

When i drop the control on a page now, the text property starts out as ""
instead of with the controls id. If someone could tell me how to get this to
properly initialize.

Thanks in advance,
- Arthur Dent.

===== BEGIN CODE ================================

Public Class LabelDesigner
Inherits ControlDesigner

Private pLabel As Label

Public Overrides Sub Initialize(ByVal component As IComponent)
MyBase.Initialize(component)
pLabel = CType(component, Label)
'pLabel.Text = pLabel.ID
End Sub

Public Property [For]() As String
Get
Return pLabel.For
End Get
Set(ByVal Value As String)
pLabel.For = Value
End Set
End Property

Protected Overrides Sub PreFilterProperties(ByVal properties As
IDictionary)
MyBase.PostFilterProperties(properties)
Dim prop As PropertyDescriptor = CType(properties("For"),
PropertyDescriptor)
If Not prop Is Nothing Then
prop = TypeDescriptor.CreateProperty(Me.GetType(), prop, New
Attribute() {New TypeConverterAttribute(GetType(ForConvertor))})
properties("For") = prop
End If
End Sub
End Class
Nov 18 '05 #1
4 1424
But first let me ask you this.

Why create a ControlDesigner just to implement a TypeConverter on a single property?

Why not this? (I'm presuming your label class is called PLabel)
[VB.Net]
Public Class PLabel
Inherits System.Web.UI.WebControls.Label

Private _for As String

<TypeConverterAttribute(GetType(ForConvertor))> _
Public Property [For] As String
Get
Return Me._for
End Get
Set(Value As String)
Me._for = Value
End Set
End Property

Public Overrides Sub OnInit()
Me._for = Me.Id
End Sub
End Class
"A Traveler" <hi*********************@yahoo.com> wrote in message news:<eL**************@TK2MSFTNGP12.phx.gbl>...
Hello all,

I have a control i wrote which inherits from asp:label. It worked fine. It
extends asp:label with a "For" property which implements the "for" attribute
of an html label tag (yes i know the latest framework vers. added this, but
i want ot get mine right as a learning exp.).

I added a designer class which turns the For property into a dropdown list
of the names of all the controls so you can simply pick one. When i added
the designer, the control no longer properly initialized its Text property
when you drop it on a webform. I THINK the problem is in then designer's
Initialize sub.

The code for my designer is shown below.

When i drop the control on a page now, the text property starts out as ""
instead of with the controls id. If someone could tell me how to get this to
properly initialize.

Thanks in advance,
- Arthur Dent.

===== BEGIN CODE ================================

Public Class LabelDesigner
Inherits ControlDesigner

Private pLabel As Label

Public Overrides Sub Initialize(ByVal component As IComponent)
MyBase.Initialize(component)
pLabel = CType(component, Label)
'pLabel.Text = pLabel.ID
End Sub

Public Property [For]() As String
Get
Return pLabel.For
End Get
Set(ByVal Value As String)
pLabel.For = Value
End Set
End Property

Protected Overrides Sub PreFilterProperties(ByVal properties As
IDictionary)
MyBase.PostFilterProperties(properties)
Dim prop As PropertyDescriptor = CType(properties("For"),
PropertyDescriptor)
If Not prop Is Nothing Then
prop = TypeDescriptor.CreateProperty(Me.GetType(), prop, New
Attribute() {New TypeConverterAttribute(GetType(ForConvertor))})
properties("For") = prop
End If
End Sub
End Class

Nov 18 '05 #2
I forgot something

Public Overrides Sub OnInit()
MyBase.OnInit() 'Forgot this line
Me._for = Me.Id
End Sub
Nov 18 '05 #3
Well, i had gotten the code from someone else who was doing the same thing,
providing the dropdown list of controls on the form. I dont know a whole lot
about all the designer and type convertor stuff.... still very new to any
advanced control design.

Thanks for the help, removing the designer did the trick. Now the base label
does properly initialize itself. However, you cant use the OnInit override
to set initial properties. Then when you close the designer and reopen it,
it reinits them and overrides and changes you might have made.

Thanks again though for your help clearing up the labels Text property.

- Arthur Dent
"WALDO" <Go**********@WALDOLand.com> wrote in message
news:9b**************************@posting.google.c om...
But first let me ask you this.

Why create a ControlDesigner just to implement a TypeConverter on a single
property?

Why not this? (I'm presuming your label class is called PLabel)
[VB.Net]
Public Class PLabel
Inherits System.Web.UI.WebControls.Label

Private _for As String

<TypeConverterAttribute(GetType(ForConvertor))> _
Public Property [For] As String
Get
Return Me._for
End Get
Set(Value As String)
Me._for = Value
End Set
End Property

Public Overrides Sub OnInit()
Me._for = Me.Id
End Sub
End Class
"A Traveler" <hi*********************@yahoo.com> wrote in message
news:<eL**************@TK2MSFTNGP12.phx.gbl>...
Hello all,

I have a control i wrote which inherits from asp:label. It worked fine.
It
extends asp:label with a "For" property which implements the "for"
attribute
of an html label tag (yes i know the latest framework vers. added this,
but
i want ot get mine right as a learning exp.).

I added a designer class which turns the For property into a dropdown
list
of the names of all the controls so you can simply pick one. When i added
the designer, the control no longer properly initialized its Text
property
when you drop it on a webform. I THINK the problem is in then designer's
Initialize sub.

The code for my designer is shown below.

When i drop the control on a page now, the text property starts out as ""
instead of with the controls id. If someone could tell me how to get this
to
properly initialize.

Thanks in advance,
- Arthur Dent.

===== BEGIN CODE ================================

Public Class LabelDesigner
Inherits ControlDesigner

Private pLabel As Label

Public Overrides Sub Initialize(ByVal component As IComponent)
MyBase.Initialize(component)
pLabel = CType(component, Label)
'pLabel.Text = pLabel.ID
End Sub

Public Property [For]() As String
Get
Return pLabel.For
End Get
Set(ByVal Value As String)
pLabel.For = Value
End Set
End Property

Protected Overrides Sub PreFilterProperties(ByVal properties As
IDictionary)
MyBase.PostFilterProperties(properties)
Dim prop As PropertyDescriptor = CType(properties("For"),
PropertyDescriptor)
If Not prop Is Nothing Then
prop = TypeDescriptor.CreateProperty(Me.GetType(), prop, New
Attribute() {New TypeConverterAttribute(GetType(ForConvertor))})
properties("For") = prop
End If
End Sub
End Class

Nov 18 '05 #4
Try this

Public Overrides Sub OnInit()
Me._for = Me.Id
MyBase.OnInit() 'Forgot this line
End Sub

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: fragget | last post by:
Hiya- I wrote a color combo box control that shows colors in the drop down part of a combo box. The control works great, however, whenever I drag any of the controls around on a form this...
4
by: Anatoly | last post by:
Put any control on web page. create Init event for ths control. Write Response.Write("here") inside this event. Compile\build\run. I never saw "here" string appear on web page. Why???
10
by: Wylbur via DotNetMonster.com | last post by:
Hello to all of you geniuses, I'm having a problem trying to get an Init handler to fire for a Placeholder control at the initialization phase. I’ve posted this problem to 3 other ASP.NET...
6
by: Shimon Sim | last post by:
I have Panel control on the page. I am handling Init event for it. It doesn't seem to fire at all. Why? Thank you Shimon.
2
by: Fred Flintstone | last post by:
I'm creating a multi-column dropdown since there isn't one. My idea is to override an Infragistics Combo and add the dropdown as a grid object. So I create a basic override of the control. The...
2
by: Fred Flintstone | last post by:
This is driving me crazy. I've put together a perfect, easy example of the problem. What I'm doing is creating a custom control, prepopulated with 4 items when dropped on a form: - Create a new...
1
by: Lucien Dol | last post by:
Hi all, Can someone help me with this, please? I've got a user control that (amongst other controls) contains a textbox. The textbox has its Anchor property set to "Left, Top, Right", meaning...
0
by: daniel.rolfe | last post by:
Hi All, I have a problem on some production servers where a particular page will postback and then never return. Eventually, the page will time out with a HttpException "Request Timed Out"...
5
by: jeremy | last post by:
I have an ASP.Net 2.0 application running on Windows Server 2003. The application displays properly in Internet Explorer, however, when I use a browser control embedded in a .net form, I get an...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.