Is there a way to access a control's value/text using the base class?
Looking at TextBox and HiddenField, System.Web.UI.Control is the most specific base class they share. Seems like a good candidate, but I don't see an obvious way to access the text/value.
I do see that both class definitions use the ControlValuePropertyAttribute to identify the property that holds their text/value... e.g. HiddenField is set to "Value", TextBox is set to "Text". Not sure how to use that info to retrieve the data, though.
Background
I have an extension method that takes the text of some web control (e.g., a TextBox) and converts it to a given type:
<Extension()> _
Public Function GetTextValue(Of resultType)(ByVal textControl As ITextControl, ByVal defaultValue As resultType) As resultType
Return ConvertValue(Of resultType)(textControl .Text, defaultValue)
End Function
Now, I need the value of a HiddenField (which does not implement the ITextControl interface). It would be easy enough to overload the function, but it would be awesome to just handle the base class and not have to deal with writing overloads anymore.
Edit - additional info
Here is an example of how the extension method is used
Dim myThing as Decimal = tbSomeWebControl.GetTextValue(Of Decimal)(0) ' Converts the textbox data to a decimal
Dim yourThang as Date = hdnSomeSecret.GetTextValue(Of Date)(Date.MinValue) ' Converts the hiddenfield data to a Date
Currently, this requires two overloads because data is accessed using the Value property in hiddenfields and the Text property in textboxes.
What's wrong with overloads? Nothing, except i'm writing nearly the same code over and over (just modifying the 1st parameter of the definition and the 1st argument of its call).