ASP.NET - 验证控件内用户控件 [英] ASP.NET - Validating Control Inside UserControl

查看:104
本文介绍了ASP.NET - 验证控件内用户控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我身边有关于DropDownList的价值管理的语言翻译特定的一个DropDownList的包装用户控件的控件。

我也有一个requried为内DropDownList的必填字段验证器。

如何通过用户控件公开此控制允许验证?

我目前得到的错误如下:

  ...无法验证。在System.Web.UI.WebControls.BaseValidator.CheckControlValidationProperty(字符串名称,弦乐propertyName的)
      在System.Web.UI.WebControls.BaseValidator.ControlPropertiesValid()

编辑:
现在,我使用...

  [ValidationPropertyAttribute(的SelectedValue)]

....用

 公共字符串的SelectedValue
{
    {返回cboI18nItems.SelectedValue; }
}

这是现在的工作,如果我检查页面的IsValid属性上回发。


解决方案

您验证应该是你的用户控件的内部,而是从页面访问。

或者设置 ValidationProperty 的用户控件


  

      
  1. 把用户控件内部的验证。它可以访问的ID
      数据输入控制。

  2.   
  3. 使用一个的CustomValidator。不要使用其ControlToValidate属性。
      相反,你自己的评价中
      功能,您将访问
      通过用户控件DROPDOWNLIST。
      你可能会做
      DropDownList的公共领域,因此它可以是
      可见,一旦你类型转换用户控件
      反对阶级的那
      用户控件。

  4.   
  5. 及其可能使用ValidationPropertyAttribute。
      您需要将属性添加到您的
      用户控件返回字符串
      数据的价值。

  6.   

这里。

I have a wrapper UserControl control around a DropDownList for managing language specific translation on the DropDownList values.

I also have a required field validator that is requried for the inner dropdownlist.

How can I expose this control via the usercontrol to allow validation?

The error I am currently getting is as follows:

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

Edit: I'm now using...

[ValidationPropertyAttribute("SelectedValue")]

.... With

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

Which is now working if I check the IsValid property of the page on postback.

解决方案

Your Validator should be inside of your UserControl but accessible from the page.

Or set ValidationProperty on the UserControl

  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.

Found here.

这篇关于ASP.NET - 验证控件内用户控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆