Kae Travis

Detect for ASP.Net page postback from Javascript

Posted on by in ASP.Net

This post describes how detect for ASP.Net page postback from Javascript. I needed to know if it was the first launch of the page or a postback from Javascript. I did this by adding a hidden field to the page:

<asp:HiddenField runat="server" ID="hdnIsPostback" />

In the page load event, I then set the value of this field to be the postback status:

protected void Page_Load(object sender, EventArgs e)
{
//set our hidden field so we can get postback value in javascript
hdnIsPostback.Value = Page.IsPostBack.ToString();
}

and then I could obtain the value (true or false) in Javascript/JQuery using the following:

if ($("#<%= hdnIsPostback.ClientID %>").val().toLowerCase() == "false") {
}

 

Detect for ASP.Net page postback from Javascript
Detect for ASP.Net page postback from Javascript

Leave a Reply