How to detect postback in javascript?

In this tutorial I will show you how can we detect poskback in javascript.

There is not direct way to do this thing.

first we need to add “Hidden” html tag to our aspx like bellow

<input type="hidden" id="_ispostback" value="<%=Page.IsPostBack.ToString()%>" />

This hidden field will store True or False depending apone whether post back occures or not.

Now in javascript we can check value of this in document.ready when page loads just like we check if it is posback or not in Page_Load event of c#.

$( document ).ready(function() {
if(document.getElementById('_ispostback').value == 'True')
// do something

This is how we can detect post back in javascript.