Setting value for javascript variable from code behind (C#)
<p>I understand the difference between Client-side and Server-side scripting. I have a javascript function and variable in my <code>MasterPage</code>:</p>

<pre><code>&lt;script language="JavaScript" type="text/javascript"&gt;
    var needToConfirm = false;
          window.onbeforeunload = confirmExit;
          function confirmExit()
          {
            if (needToConfirm)
            {
              needToConfirm = false;
              return "Currently in edit mode. If you leave the page now then you will lose unsaved changes."
            }
          }
&lt;/script&gt;
</code></pre>

<p>Given the fact that on my ASP.NET (Client-side) I can change the value of my <code>needToConfirm</code> variable to <code>true</code> <code>onClientClick</code> but by default it is false. Here's an example.</p>

<pre><code> &lt;asp:Button ID="btnEdit" runat="server" Text="  Edit  " onclick="btnEdit_Click" OnClientClick="needToConfirm = true;" /&gt;
</code></pre>

<p>Now the question here is when on the C# (Server-side) I have to set the <code>needToConfirm</code> to true under an <code>if-statement</code> but not necessarily on <code>Page_Load</code>:</p>

<pre><code>private void SetDefault()

    if (Session[def.ID_CUST] != null)
    {
          //I want to change the variable value here
    }
}
</code></pre>

<p>Thanks.</p>

<p><strong>UPDATE</strong></p>

<p>I'm using .NET 2.0 Classic and WebForms</p>
