Skip to content Skip to sidebar Skip to footer

How Can I Determine Postback Value In Window.onunload?

In our project we are deleting something after the user left the page. We are using window.unload event for doing this. window.onunload = function() { // delete something } We a

Solution 1:

that's the trick...

if you add onsubmit attribute to your form tag:

<form id="form1" onsubmit="return yourPostBack()">

and than write your own function:

function yourPostBack()
{
  _isPostBack = true;
  returntrue;
}

and finally in the page load:

if (IsPostBack)
{
  ScriptManager.RegisterClientScriptBlock(this, this.GetType(), Guid.NewGuid().ToString(), "_isPostBack = false;", true);
}

with this method you can understand that it is postback or not, in window.onunload

Solution 2:

I hope i am on the right track here,

As i understand, the OnUnload() is ClientSide, and therefore you don't have the server objects what you can do... is save the value in a hidden field.

As i am used to PHP you can even embed the value in a Javascript variable Dont know if this applys to ASP.NET:

<scriptlanguage="javascript">varMyServerVariable = "<?PHPecho MyServerVariable ?>"
if(MyServerVariable == "Blah...")
{
}
</script>

translates to

<scriptlanguage="javascript">varMyServerVariable = "VALUE"if(MyServerVariable == "Blah...")
{
}
</script>

But same thing can be done with <asp:Label /> , i am sure...

Post a Comment for "How Can I Determine Postback Value In Window.onunload?"