ASP.NET Form Validation and Jquery

Published by on
Tags:

I had a situation where I wanted a loading icon to appear when the user clicked submit in an ASP.NET form and the button to be hidden. However I didn't want the image to display if the form failed the client side validation.

The solution is to call the Page_ClientValidate method that ASP.NET uses. It takes one parameter which is the name of the validation group the button belongs to.

$(function(){
  var button = $("#<%=button.ClientID%>");
  var loadingImage = $("#loadingImage");
  
  button.click(function(){
    if(Page_ClientValidate("")){
      button.css("display","none");
      loadingImage.css("display","block");   
    }
  });  
});
 

All blogs tagged with ' javascript'

Projects

Have you read?

ELMAH Configuration



Blogs by date