|
-
Oct 10th, 2005, 05:31 PM
#1
Thread Starter
Junior Member
Inheriting from existing webcontrols - How to persist the value in design time?
Hi all, I've got some questions about inheritating from existing WebControls. The questions may sound stupid to expert like you, but it really causing many dizzy circles in my head. Please kindly give me a hand
First off, I have created a very simple webcontrol, which inherits from WebControls.Label.
VB Code:
Public Class MyInheritedLabel
Inherits System.Web.UI.WebControls.Label
Private m_MyPrefix As String
<Bindable(True), _
DefaultValue("Any Prefix"), _
PersistenceMode(PersistenceMode.InnerProperty), _
DesignerSerializationVisibility(DesignerSerializationVisibility.Content)> _
Public Property MyPrefix() As String
Get
Return m_MyPrefix
End Get
Set(ByVal Value As String)
m_MyPrefix = Value
End Set
End Property
Protected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter)
writer.InnerWriter.Write(m_MyPrefix & Text)
End Sub
End Class
Everything goes fine, I did successfully compiled it and add them to my toolbox 
However, when I use the MyInheritedLabel in another project, I found a strange behaviour. Like usual, I drag the control to my webform and assign some values to the MyPrefix property (though the property window, not from the code). Pressed F5 and have the expected result correctly. However, when I close the form (and save it to disk, of course ) in the VS IDE and then open it again, all the newly assigned value of MyPrefix were gone! ah.. I was expecting the value to be persistable, just like other properties we've got in a normal WebControls.Label. Wouldn't it be wierd to have all the [Text] in WebControls.Label cleared everytime you open the webform in IDE? 
So I think it is reasonable to expect the same behaviour from the custom properties i added (in this case, the MyPrefix property). I've did a lot of searching, but never have a clue found. So, I'll be glad to have some information or clue from you guys. Many thanks!!
My 2nd question is somehow embrassing As you've seen, I've put DefaultValue("Any Prefix") before the property declaration. However the default value didn't shown up in the property window. Again, please give me a hand if you got any hints.
Thanks in advance
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|