This scenario is pretty common, but not supported by the framework directly.
Here's what I do to solve this:
1. Create a function that disables all validators on the page. You can use code like this for that:
for (var i = 0; i < Page_Validators.length; i++)
Page_Validators[i].enabled = false;
2. As parameters for this function, allow the names of the controls you *do* want to validate from one button click:
for(var j = 0; j <= arguments.length - 1; j++)
document.getElementById(arguments[j]).enabled = true;
3. Add an onclick
attribute to the button that causes validation (use: MyButton.Attributes.Add
) and have it call the function from step 1. As arguments, pass one or more ClientID
page, and link to that in your ASPX page.
' as the control you want to validate. The code in the function disables all validators, and then reenables the valUserName
validator. The same way, if you click button 2 and pass valSearch
, all validators are enabled, except for valSearch
You may need to repeat this process for the Validation Summaries (you'll find an array called Page_ValidationSummaries
at the end of your page that contains all their names). In the onclick
of the button, disable them all, except for the one that is attached to the button.
Hope this helps, and if you have any questions, feel free to ask them here. Working with the validators from client side script isn't the most intuitive thing to do.
Everyone is unique, except for me.