Peanut
Peanut

Reputation: 19407

Use javascript to determine if an ASP.NET page is a postback

Is it possible to determine if an ASP.NET page is a postback from javascript? So basically a javascript equivalent of C# Page.IsPostBack.

Thanks.

Upvotes: 5

Views: 7964

Answers (3)

Bob
Bob

Reputation: 99734

I would just put a render tag in the javascript

var isPostBack = <%= Page.IsPostBack ? "true" : "false" %>;

Putting the "true" and "false" as strings should be done to eliminate any possible issues converting the type to a string as in C# true.ToString() is usually "True" which is an error in javascript.

Upvotes: 14

Robb C
Robb C

Reputation: 152

I'm not exactly sure of what you are trying to do but you might want to look into the PageRequestManagerClass:

http://www.asp.net/AJAX/Documentation/Live/ClientReference/Sys.WebForms/PageRequestManagerClass/default.aspx

It exposes events for all different parts of the request.

Upvotes: 0

Joel Coehoorn
Joel Coehoorn

Reputation: 415820

Sure. Just use your server code to write out a javascript flag, if you really need this.

But I suspect you're barking up the wrong tree here.

Upvotes: 2

Related Questions