5

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.

3 Answers 3

14

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.

Sign up to request clarification or add additional context in comments.

2 Comments

This is something we do as well, very handy +1
Of course, at this point, it is technically "wasPostBack". :P
2

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.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.