Controlling html/xml tag of custom control from control code

H

henrique de souza

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 “Hello”, 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’s 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
DesignerSerializationVisibility(DesignerSerializationVisibility.Content)
, _
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

<Bindable(True), Browsable(True), _
Category("CIMS"), Description("Something"), _

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

<Bindable(True), Category("Appearance"), DefaultValue("")> _
Public Property [Text]() As String
Get
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
Controls.Clear()
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
HtmlTextWriter)

output.Write([Text])
End Sub

End Class


Henrique de Souza (MCP - Analysts International)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,989
Messages
2,570,207
Members
46,787
Latest member
SybilStern

Latest Threads

Top