I'm looping through an array of controls and need to know which controls an end-user has the ability to (via JavaScript or directly) change the value that gets posted back. Where can I find such a list?
So far I have this:
Private Function IsEditableControl(ByVal control As Control) As Boolean
Return TypeOf control Is IEditableTextControl _
OrElse TypeOf control Is ICheckBoxControl _
OrElse GetType(ListControl).IsAssignableFrom(control.GetType()) _
OrElse GetType(HiddenField).IsAssignableFrom(control.GetType())
End Function
I'm rather sure that you only need to know if that control implements IPostBackDataHandler.
Public Shared Function IsControlEditable(ByVal ctrl As Control) As Boolean
Return TypeOf ctrl Is IPostBackDataHandler
End Function
"If you want a server control you design to examine form data that is posted back to the server by the client, you must implement the IPostBackDataHandler interface. The contract that this interface defines allows a server control to determine whether its state should be altered as a result of the post back, and to raise the appropriate events."
These are the classes that implement it:
The big advantage of checking for implementing IPostBackDataHandler is that your function works also in future(with controls that will be added to the framework) and for third party controls.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With