473,734 Members | 2,511 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(ByVa l component As IComponent)
MyBase.Initiali ze(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 PreFilterProper ties(ByVal properties As
IDictionary)
MyBase.PostFilt erProperties(pr operties)
Dim prop As PropertyDescrip tor = CType(propertie s("For"),
PropertyDescrip tor)
If Not prop Is Nothing Then
prop = TypeDescriptor. CreateProperty( Me.GetType(), prop, New
Attribute() {New TypeConverterAt tribute(GetType (ForConvertor)) })
properties("For ") = prop
End If
End Sub
End Class
Nov 18 '05 #1
4 1455
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.W ebControls.Labe l

Private _for As String

<TypeConverterA ttribute(GetTyp e(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******* *******@TK2MSFT NGP12.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(ByVa l component As IComponent)
MyBase.Initiali ze(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 PreFilterProper ties(ByVal properties As
IDictionary)
MyBase.PostFilt erProperties(pr operties)
Dim prop As PropertyDescrip tor = CType(propertie s("For"),
PropertyDescrip tor)
If Not prop Is Nothing Then
prop = TypeDescriptor. CreateProperty( Me.GetType(), prop, New
Attribute() {New TypeConverterAt tribute(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**********@W ALDOLand.com> wrote in message
news:9b******** *************** ***@posting.goo gle.com...
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.W ebControls.Labe l

Private _for As String

<TypeConverterA ttribute(GetTyp e(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******* *******@TK2MSFT NGP12.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(ByVa l component As IComponent)
MyBase.Initiali ze(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 PreFilterProper ties(ByVal properties As
IDictionary)
MyBase.PostFilt erProperties(pr operties)
Dim prop As PropertyDescrip tor = CType(propertie s("For"),
PropertyDescrip tor)
If Not prop Is Nothing Then
prop = TypeDescriptor. CreateProperty( Me.GetType(), prop, New
Attribute() {New TypeConverterAt tribute(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
3416
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 control is on (the color control) the following code gets added to the form the control sits on.
4
3903
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
3876
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 forums, and noone wants to touch it. I tried to attach a literal control to a placeholder: <>-<>-<>-<>-<>-<>-<>-<>-<>-<>-<>-<>
6
2207
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
2778
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 first thing I want the control to do is kill the default button and add a new one. So in the initialization (New) area of the control I add the code to do that: Me.DropDownButtonDisplayStyle = Infragistics.Win.ButtonDisplayStyle.Never Dim...
2
1136
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 Control Library project. - Inherit System.Windows.Forms.Combobox - In New(), add this: Me.Items.Add("Test1") Me.Items.Add("Test2")
1
1928
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 that it will stretch automatically when the control is resized on a form or other user control. When in design mode I look at the control by itself (rather than dropped on a form) the control has a certain size (let's call this SizeA).
0
1176
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" error. When I turn on tracing, reproduce the error and view the trace using Trace.axd some things look a little odd. I have attached the output for the page in question below. I ommitted the Server Variables and encoded viewstate data just so the
5
2068
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 error and am directed to the Windows Application Event Log. The following message is logged: ------------- Source: ASP.NET 1.1.4322.0 Event ID: 1062
0
8946
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9449
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9310
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9236
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9182
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6735
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6031
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3261
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2180
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.