Rob
9/29/2008 10:43:00 AM
Dear all,
I'm having to pass into a method a WebControl byref.
Once passed I have to determine it's type, either;
System.Web.UI.WebControls.TextBox
or
System.Web.UI.WebControls.DropDownList
If the former, I then need to query the ReadOnly property for it, and
this is where I am stuck...
If I create a new TextBox, I can set the ReadOnly property to True|
False etc. However, when I pass a WebControl and then CTYPE it to a
TextBox, I am unable to access this property, thus I cannot query its
value.
Code:
Private Sub SetCssClassForField(ByRef webControl As
System.Web.UI.WebControls.WebControl)
Select Case webControl.GetType.ToString
Case "System.Web.UI.WebControls.TextBox"
webControl = CType(webControl,
System.Web.UI.WebControls.TextBox)
Select Case webControl.Attributes.Item("ReadOnly")
Case True
webControl.CssClass = "rotb"
Case False
webControl.CssClass = "tb"
End Select
Case "System.Web.UI.WebControls.DropDownList"
webControl = CType(webControl, DropDownList)
Select Case webControl.Enabled
Case True
webControl.CssClass = "ddl"
Case False
webControl.CssClass = "roddl"
End Select
End Select
End Sub
I had hoped I might be able to access it as an "attribute" (reference
line 5 above) - but that doesn't work either...
So, can anyone suggest to me how I might go about doing this? I am
basically trying to specify which cssClass to use depending on whether
the control has been set as ReadOnly or not.
I'm also going to have a problem with the DropDownList as that doesn't
natively have a ReadOnly property at all, presumably for that one I
use "Enabled" ?
Any information would be appreciated.
Thanks in advance,
Rob Meade