This post has been migrated from www.experimentsincode.com, we apologise if some of the images or content is missing

This post has been migrated, original date 06 Oct 2009 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");
    }
  });
});
comments powered by Disqus