开发者

disabling ASP.NEt Validtor such that its disabled on postback

I am trying to disable ASP.Net Validator such that its disabled on postback.

I am disabling the validator on client side using

$('.c_MyValidator').each(function() {
     ValidatorEnable(document.getElementById($(this).attr('id')), false);
});

but when the page postbacks, my page is still invalid开发者_如何转开发. I am in UserControl (.ascx) so no override for Validate() for me.

How can I disable the validator such that its enabled=false when the page postbacks.

Any ideas?


There is an example for your scenario here. Basically in server side code, set the enabled property of the validator to the checked property of the checkbox (as well as call the client ValidatorEnable). Use the Page_Load event of your user control because there is no Validate method.

public partial class CheckboxAndValidator : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        validator.Enabled = cbControlValidation.Checked;
    }
}

What you can't do is validate your page in the Page_Load event. This is too early and needs to be done later in the page life-cycle once the user control has done it's bit.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜