Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 777
Peanut Avatar asked Jan 02 '09 16:01

Peanut


2 Answers

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.

like image 81
Bob Avatar answered Nov 10 '22 09:11

Bob


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.

like image 2
Joel Coehoorn Avatar answered Nov 10 '22 11:11

Joel Coehoorn