• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 415
  • Last Modified:

Disable ASP.NET Form validators using Jquery button click

I have created a simple login page, using ASP.NET 4.5, which has the standard RequiredField validators, assigned to the username and password.

I'm using asp.net identity 1.0 to validate the user, which unfortunately, out of the box, doesnt offer a reset / lost password fucntion, so I am having to roll out my own version.

The problem, I am facing, is being able to disable to validators, when the user clicks the 'Reset Password' button. The button, calls a WebMethod, which in turns, calls a method to actually do the resetting.

Below is what I have, which isn't working at all. In fact, the console.log isnt even being fired.

<div class="form-group">
								<div class="col-sm-12">
									<div class="input-group">
										<span class="input-group-addon"><i class="fa fa-user"></i></span>
                                        <asp:TextBox runat="server" ID="userName" CssClass="form-control" placeholder="Username.." />
									</div>
                                    <asp:RequiredFieldValidator runat="server" ControlToValidate="userName"
                                            CssClass="text-danger" ErrorMessage="The user name field is required."/>
								</div>
							</div>
							<div class="form-group">
								<div class="col-sm-12">
									<div class="input-group">
										<span class="input-group-addon"><i class="fa fa-lock"></i></span>
                                        <asp:TextBox runat="server" ID="password" TextMode="Password" CssClass="form-control" placeholder="Password.." />
									</div>
                                         <asp:RequiredFieldValidator runat="server" ControlToValidate="password" CssClass="text-danger" ErrorMessage="The password field is required." />
								</div>
							</div>

Open in new window


$("#btnResetPassword").click(function(e) {
    e.preventDefault();
    console.log("We have clicked the reset button");
    disableAllValidators();

    $("#modalLostPassword").modal("show");
});


function disableAllValidators() {
    console.log(document.getElementById("<%=userName.ClientID %>"));
    document.getElementById("<%=userName.ClientID %>").enabled = false;
}

Open in new window


Can you please suggest, how I can disable the validators, as soon as the Reset Password button is clicked?
0
Wayne Atherton
Asked:
Wayne Atherton
1 Solution
 
Randy DownsOWNERCommented:
Try this

Something you may be able to adapt to your needs (this will disable all the validators via client script):

if (typeof Page_Validators != 'undefined') {
        for (i = 0; i <= Page_Validators.length; i++) {
            var vldGrp = null;
            if (Page_Validators[i] != null) {
                vldGrp = Page_Validators[i].validationGroup;
                ValidatorEnable(Page_Validators[i], false);
            }
        }
    };

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now