I have a gridview, with paging enabled.
This is the link when I want to go to second page
<a href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$gv','Page$2')">
The problem is that I require to run the CheckValid() function before paging is done – user cannot page with invalid details. How can I set the HREF to allow this?
<a href= "if Checkvalid() then "javascript:__doPostBack('ctl00$ContentPlaceHolder1$gv','Page$2')"">
In your case, pagers are generated by ASP.NET, so you can’t do much server-side.
You have to run a client-side script which, in steps:
1-Finds the pager anchors
2-replace (and store) their href with an onclick function
3-create your validation function that, if successfull, calls the original stored function “__doPostBack”.
That’s not so complicated if you get the help of client-side tools like Firebug or Chrome developer tools.