Validate - Web User Control

老子叫甜甜 提交于 2019-12-01 13:56:18

There are two steps to integrating your custom server controls with the validation framework.

(1) Server side: you'll need to add a ValidationPropertyAttribute to your class, so the validation framwework knows what to look at when validating:

[ValidationProperty("SelectedDate")]
public class MyDateControl : WebControl
{
    public DateTime? SelectedDate { get { ... } set { ... } }
} 

(2) To hook up with client side validation, you have to make sure there's an input tag associated with your control. One way of doing that is rendering an <input type="hidden"> as the first child tag of your web control's HTML. The validation framework will pick up on that. The remaining thing to do here, is to set this hidden field through JavaScript each time your one drop downs changes.

This way, you can tie in with the existing validation controls. If you want different way to validate, you should look at a CustomValidator.

You want to use the CustomValidator control for this. See this tutorial that explains how to implement it with both a client-side and server-side version of the validation.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!