I understand the difference between client and server scenarios. I have a javascript function and a variable in my MasterPage :
<script language="JavaScript" type="text/javascript"> 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." } } </script>
Given the fact that on my ASP.NET (client side) I can change the value of my needToConfirm variable to true onClientClick , but the default value is false. Here is an example.
<asp:Button ID="btnEdit" runat="server" Text=" Edit " onclick="btnEdit_Click" OnClientClick="needToConfirm = true;" />
Now the question is here, when in C # (server side) I have to set needToConfirm to true with an if-statement , but not necessarily to Page_Load :
private void SetDefault() if (Session[def.ID_CUST] != null) {
Thanks.
UPDATE
I am using .NET 2.0 Classic and WebForms
Christian mark
source share