LibraRocks
LibraRocks

Reputation: 335

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?

Upvotes: 1

Views: 399

Answers (1)

Tom
Tom

Reputation: 845

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.

Upvotes: 2

Related Questions