|
-
Apr 23rd, 2004, 01:22 PM
#1
Thread Starter
Frenzied Member
Custom Control
Okay, here is the dilemma.
I have created a custom control that consists of a textbox and an optional required field validator.
Everything works fine except for one minor problem.
I have overridden some of the properties, such as Font, BackColor, BorderStyle, etc.. and have made these properties invisible in the properties window, using <Browsable(False)> _.
The problem is, in the code-behind (using VS.NET) Intellisense still displays the hidden properties.
All the examples I have seen say to use the EditorBrowsable(EditorBrowsableState.Never) attribute to prevent Intellisense from displaying it, but this isn't working....
Here's a sample control I created to test this.
Code:
Imports System
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.ComponentModel
Imports System.Drawing
Public Class MyTextBox
Inherits TextBox
Private txtBox As TextBox
Public Sub New()
txtBox = New TextBox
End Sub
Protected Overrides Sub render(ByVal writer As HtmlTextWriter)
MyBase.Render(writer)
End Sub
Browsable - prevents the property from being seen in the properties window...This works
EditorBrowsable - prevents the property from being referenced in intellisense
in the code-behind...This doesn't work!
Obsolete - Prevents a developer from using this property.
If the developer tries to use this property in the code-behind
and compile it. The message is supposed to display in the
task list as an error.
"This property isn't supported."...This doesn't work!
<Browsable(False), _
EditorBrowsable(EditorBrowsableState.Never), _
Obsolete("This property isn't supported.", True)> _
Public Overrides Property BackColor() As Color
Get
Return Nothing
End Get
Set(ByVal Value As Color)
txtBox.BackColor = Nothing
End Set
End Property
End Class
Any ideas why???
Being educated does not make you intelligent.
Need a weekend getaway??? Come Visit
-
Apr 23rd, 2004, 06:07 PM
#2
I wonder how many charact
Well, I noticed if you use a non-existing property name, the intended effect occurs.
If you inherit from a control, and try to suppress what is declared publicly browsable in the parent, the intended effect does not occur.
In the case of textbox, (and I also tried Label), even though the property is declared Overridable, it doesn't seem you can suppress the MetaTag (EditorBrowsable) associated with that property in the parent.
Strangely, of the three you presented, this 'glitch' only happens with the EditorBrowsable attribute. I'm not sure if its a bug, or its has to do with how the EditorBrowsable attribute is defined in the server controls that implement it, that prevent it from working.
So after trying all that, and using the control from a dll instead of within the project, i googled and found this:
http://www.dotnet247.com/247referenc...29/148631.aspx
Bottom line: I'm guessing there are some undocumented attributes (or perhaps just reasons) that prevent inheriting children from hiding properties declared as browseable in the parent.
As far as a workaround, well, you could make your inherited control a composite control (webcontrol) that internally encompasses a textbox, and only expose the properties that are needed. I'm pretty sure for example, the WebControl class does not expose a BackColor property.
Last edited by nemaroller; Apr 23rd, 2004 at 06:24 PM.
-
Apr 23rd, 2004, 10:10 PM
#3
Frenzied Member
public class lite : System.Web.UI.Control
Magiaus
If I helped give me some points.
-
Apr 23rd, 2004, 10:54 PM
#4
Thread Starter
Frenzied Member
Yes, WebControl exposes a BackColor Property among others.
My assumption/test is you can override the inherited properties for the WebControl base class, but you can't suppress them from showing up in intellisense.
I did a test and created a base control (myTextBox) which inherited from the WebControl class. Then I inherited my base control to create a custom control (myTextBox2).
I did an override of the WebControls BackColor property in my base control (myTextBox), and I was able to suppress the BackColor property in my custom Control (myTextBox2) and prevent the BackColor property from showing up in intellisense.
Example:
VB Code:
Public Class myTextBox
Inherits WebControl
[color=red]Override the WebControls BackColor Property[/color]
Public Overrides Property BackColor() As Color
Get
'code here
End Get
Set(ByVal Value As Integer)
'code here
End Set
End
End Class
Then I inherit myTextBox
VB Code:
Public Class myTextBox2
Inherits myTextBox
'I was able to suppress the BackColor property from
'showing up in intellisense by doing this.
[color=red]Override myTextBoxes BackColor property[/color]
<Browsable(False), _
EditorBrowsable(EditorBrowsableState.Never), _
Obsolete("This control does not support this property.", True)> _
Public Overrides Property BackColor() As Color
Get
'code here
End Get
Set(ByVal Value As Integer)
'code here
End Set
End Property
End Class
Being educated does not make you intelligent.
Need a weekend getaway??? Come Visit
-
Apr 24th, 2004, 08:02 AM
#5
Frenzied Member
new internal System.Drawing.Color BackColor{get{;}}
you the assembly dev could see backcolor byt no one else should be able to. But then again I don't think that really works either. Your best be is to either inherit from control or from the interfaces IParssorAccesory, IStateManager, IComponet, IDataBind. Of cour the you have to handle state and whast not
Magiaus
If I helped give me some points.
-
Apr 24th, 2004, 11:22 PM
#6
I wonder how many charact
Originally posted by Memnoch1207
......
So you were able to solve this then by simply not inheriting your custom 'textbox' from the System.Web.UI.WebControls.TextBox, but rather the WebControl class. Which is how you create a composite control btw.
So perhaps then, all server controls, including Label, Checkbox, etc, have these limiting attributes in their decleration, that disallow suppression of the EditorBrowseable attribute.
I find that pretty strange the .Net framework was made this way.
-
Apr 25th, 2004, 01:31 AM
#7
Thread Starter
Frenzied Member
It didn't matter if I inherited from WebControl or WebControl.TextBox.
Apparently you can't suppress the webcontrols properties directly. I was able to solve it by creating a class that inherits webcontrol and overrides the webcontrols properties.
Then creating another class that inherits from the first class I created, then overriding it's properties.
Being educated does not make you intelligent.
Need a weekend getaway??? Come Visit
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
|