Sunday, August 14, 2011

Detecting Post Back in Through Javascript


Some time we need to do some functionality in a page using JavaScript when page load for the first time only, The best way to do is to detect Post back and then perform the functionlaity in JavaScript.
Here is the way to achive.
Place the following code in javaScript block

 window.onload = isPostBack;    function isPostBack()    
{     
  var chkPostBack = '<%= Page.IsPostBack ? "true" : "false" %>';
       if(chkPostBack == 'false')
       {
        alert('Page loaded First Time');
       }   
     else
       {
         alert('Post back');
       }
 }
Happy Coding...
Related Posts Plugin for WordPress, Blogger...