Byte My Data

A personal collection of advice and solutions I've used.

About the author

Something about the author

Check for IsPostBack using javascript

I found this in an MSDN post.

You can't do it directly but if you add the following to the server side Page_Load in the code behind, you can check for the javascript variable on the client side.

server side:

        protected void Page_Load(object sender, EventArgs e)
        {
            // NOTE: the following uses an overload of RegisterClientScriptBlock()
            // that will surround our string with the needed script tags .
            ClientScript.RegisterClientScriptBlock(GetType(), "IsPostBack", string.Format("var isPostBack = {0};", (IsPostBack ? "true" : "false")), true);
        }

client side:

<head>
...
   
...
</head>
<body onload="doSomething();">

Categories: ASP.NET | C# | Javascript
Permalink | Comments (2) | Post RSSRSS comment feed

Comments

Actual Tests Sri Lanka

Saturday, February 11, 2012 11:08 AM

Actual Tests

This is a fantastic well written article. Gave me an insight into what Framework to use.

Exam Questions Russia

Saturday, February 11, 2012 11:09 AM

Exam Questions

Amazing post. first time visiting your blog, very good stuff.

Add comment




  Country flag

biuquote
  • Comment
  • Preview
Loading