Controlling html/xml tag of custom control from control code

Controlling html/xml tag of custom control from control code

Post by henrique d » Sat, 24 Apr 2004 23:40:48

Hi all,

I have a custom control (simple, not composite) that has two properties,
Text and Maxlength. When I change the text property from the property
window to ello on the Set command of the text property (which means,
the code of the custom control), I set the property Maxlength to 13. The
value changes and it displayed the property window, under Maxlength as
13. But when I look at the html tag, it still shows whatever I had there
before. Here is the code. I guess my objective is to be able to set a
property in code (based on the value of another property, when it gets
changed) and reflect the change not only in the property window but also
in the html/xml tag of the custom control. I tried
, _
NotifyParentProperty(True), _
PersistenceMode(PersistenceMode.Attribute) on my maxlength property,
but it still doesn't seem to work!

Public Class TextControl
Inherits System.Web.UI.WebControls.WebControl
Private [text_] As String = "[default]"
Private _MaxLength As Integer

< Category("CIMS"), Description("Something"), _

, _
NotifyParentProperty(True), _
PersistenceMode(PersistenceMode.Attribute>> _
Public Property MaxLength() As Integer
Return _MaxLength
End Get
Set(ByVal Value As Integer)
_MaxLength = Value
End Set
End Property

< _
Public Property [Text]() As String
Dim o As Object = ViewState("Text")
'Return IIf(o Is Nothing, String.Empty, CStr(o))
Return [text_]
End Get
Set(ByVal Value As String)
If HasControls() Then
End If
If Value = "hello" Then Me.MaxLength = 13
ViewState("Text") = Value
End Set
End Property

'Public Sub New()
' [text_] = "Test phrase"
'End Sub

Protected Overrides Sub rendercontents(ByVal output As

End Sub

End Class

Henrique de Souza (MCP - Analysts International)

*** Sent via Developersdex ***
Don't just participate in USENET...get rewarded for it!

1. difference between HTML controls, HTML server controls , ASP.Net controls?

2. Custom Container Control Changes the Input Tag Names of Child Controls???

I have a custom control that derives from the WebControls.Panel class.

In a given ASPX document, I have an instance of my custom control with ID
set to "MyControl".

Then I put a WebControls.TextBox control inside my custom control with ID
set to "MyTextBox".

When this page renderes, inspection of the HTML source shows that the Name
attribute of the input tag generated from MyTextBox is now actually
"MyControl:MyTextBox" and not just "MyTextBox".

Trying a similiar scenario, but using the standard WebControls.Panel as a
container instead of my panel-derived custom control, the input tag Name
attribute is as expected, "MyTextBox".

So, I figure I'm cleary doing something wrong.

Any thoughts?


3. Creating custom controls out of more complex control types (eg change password control)

4. Can I control existing HTML by using a custom control?

5. How do I get a custom Control Designer to write to the HTML of my control?

6. Showing 1 control inside a 2nd control where the 2nd control is a derived control.

7. mixing HTML controls with code behind controls

8. this.Controls.Add(Control) Does Not Add Control to child collection (this.Controls.Count == 0)

9. How to address control within templated custom control from code behind

10. ASP.Net Server Control (Web Custom Control) Code Update Problem

11. Capturing event from other custom control within another custom control

12. Help on HTML server control vs HTML control

13. zooming a custom control - layout custom controls in grid

14. Custom Control : One custom property to array of controls

15. How to extend control to add custom html tag ?