Monday, May 20, 2024
Homepage · c#
 Popular · Latest · Hot · Upcoming
109
rated 0 times [  113] [ 4]  / answers: 1 / hits: 34232  / 11 Years ago, fri, may 10, 2013, 12:00:00

I understand the difference between Client-side and Server-side scripting. I have a javascript function and 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 by default it is false. Here's an example.



 <asp:Button ID=btnEdit runat=server Text=  Edit   onclick=btnEdit_Click OnClientClick=needToConfirm = true; />


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



private void SetDefault()

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


Thanks.



UPDATE



I'm using .NET 2.0 Classic and WebForms


More From » c#

 Answers
10

in code behind:



ScriptManager.RegisterStartupScript(this, this.GetType(), , urFunction('urValHere');, true);


on client-side:



function urFunction(urParam) {
//do what u want here
//use urParam
}

[#78316] Wednesday, May 8, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jaylanw

Total Points: 730
Total Questions: 98
Total Answers: 95

Location: Saudi Arabia
Member since Tue, Nov 29, 2022
2 Years ago
;