加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

ASP.NET – 验证UserControl内部的控件

发布时间:2020-12-16 07:02:53 所属栏目:asp.Net 来源:网络整理
导读:我有一个围绕DropDownList的包装器UserControl控件,用于管理DropDownList值的语言特定转换. 我还有一个必需的字段验证器,需要内部下拉列表. 如何通过usercontrol公开此控件以允许验证? 我目前得到的错误如下: ... cannot be validated. at System.Web.UI.W
我有一个围绕DropDownList的包装器UserControl控件,用于管理DropDownList值的语言特定转换.

我还有一个必需的字段验证器,需要内部下拉列表.

如何通过usercontrol公开此控件以允许验证?

我目前得到的错误如下:

... cannot be validated. at System.Web.UI.WebControls.BaseValidator.CheckControlValidationProperty(String name,String propertyName)
      at System.Web.UI.WebControls.BaseValidator.ControlPropertiesValid()

编辑:
我现在正在使用……

[ValidationPropertyAttribute("SelectedValue")]

….随着

public string SelectedValue
{
    get { return cboI18nItems.SelectedValue; }
}

如果我在回发时检查页面的IsValid属性,那么现在正在工作.

解决方法

您的Validator应位于UserControl内部,但可从页面访问.

或者在UserControl上设置ValidationProperty

  1. Put the validator inside the UserControl. It can access the ID of
    the data entry control.
  2. Use a CustomValidator. Do not use its ControlToValidate property.
    Instead,within your own evaluation
    function you will access the
    DropDownList through the UserControl.
    You probably will make the
    DropDownList field Public so it can be
    seen once you typecast the UserControl
    object to the class of that
    UserControl.
  3. Its possible to use the ValidationPropertyAttribute.
    You need to add a property to your
    usercontrol that returns a string
    value of the data.

发现here.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读