如何判断控件或控件界面是否可由用户编辑?(How to tell if the control or control interface is editable by the user?)

编程入门 行业动态 更新时间:2024-10-27 18:31:38
如何判断控件或控件界面是否可由用户编辑?(How to tell if the control or control interface is editable by the user?)

我循环遍历一系列控件,需要知道最终用户有哪些控件能够(通过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 Function

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

最满意答案

我很确定你只需要知道该控件是否实现了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 TextBox

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.

更多推荐

本文发布于:2023-07-27 17:56:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1293635.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:控件   可由   如何判断   界面   编辑

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!