Validation plays a key role whenever we take inputs from the user. For this, ASP.NET provides us with few validator controls that are used a lot in web applications. Nowadays, in our application, we have several sections in our web pages. And also, we populate some data based on the user’s input. So several times, it requires to validate the page partially not the entire page,
while earlier we used to have a single submit button and there we need to validate the page.
AJAX also played a key role, for partial post back, initiate a call to server, etc., which requires to validate a part of the page.
So, in these scenarios, our earlier approach of validation would not work. In this kind of scenario, I will discuss few things that will be very helpful.
First, I would suggest to divide your page in some logical section, those you might need to validate at certain points. Then, assign a different group name to the validators on those sections.
So before initiating the Ajax call, you need to validate the user inputs. This can be easily done with the following method.
You need to call
Page_ClientValidate() method, this method has two flavors:
Page_ClientValidate() it fires all the validators on the page and returns
false, if it fails
Page_ClientValidate(‘groupname’), this method fires all the validators having the passed groupname and returns
false if any validator fails
if(Page_ClientValidate('groupname') == false)
So this validator wont be fired till you enable it again. You can enable it as:
Hope you like this post and find it to be useful.