我循环遍历一系列控件,需要知道最终用户有哪些控件能够(通过JavaScript或直接)更改返回的值。 我在哪里可以找到这样的清单?
到目前为止我有这个:
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 FunctionI'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最满意答案
我很确定你只需要知道该控件是否实现了IPostBackDataHandler 。
Public Shared Function IsControlEditable(ByVal ctrl As Control) As Boolean Return TypeOf ctrl Is IPostBackDataHandler End Function“如果您想要设计一个服务器控件来检查客户端发回服务器的表单数据,则必须实现IPostBackDataHandler接口。此接口定义的合同允许服务器控件确定其状态是否应更改为回复的结果,并提出适当的事件。“
这些是实现它的类:
复选框 CheckBoxList的 下拉列表 HtmlInputCheckBox HtmlInputFile HtmlInputHidden HtmlInputImage HtmlInputRadioButton 的HtmlInputText HtmlSelect HtmlTextArea 的ImageButton 列表框 单选按钮列表 文本框检查实现IPostBackDataHandler的一大优势是,您的函数在将来(带有将添加到框架的控件)和第三方控件中也可以正常工作。
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:
CheckBox CheckBoxList DropDownList HtmlInputCheckBox HtmlInputFile HtmlInputHidden HtmlInputImage HtmlInputRadioButton HtmlInputText HtmlSelect HtmlTextArea ImageButton ListBox RadioButtonList TextBoxThe 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.
更多推荐
发布评论