Skip to main content
Home Forums Silverlight Programming Programming with JavaScript Changing Javascript Function definition from Silverlight
1 replies. Latest Post by vinCracker on June 23, 2009.
(0)
misterken
Member
14 points
31 Posts
06-22-2009 2:52 AM |
In my aspx page I have this setup:
<body onbeforeunload="ConfirmIEClose()">
From within the ASP.NET c#, I can do this and it works:
const string _STARTUPSCRIPT = "StartUpScript";protected void Button2_Click(object sender, EventArgs e){ string value = "WARNING! ANY UNSAVED DATA WILL BE LOST."; string startUpScript = string.Format("<script language="javascript" type="text/javascript"> function ConfirmIEClose() { if ((window.event.clientX < 0) || (window.event.clientY < 0)) window.event.returnValue = '{0}'; } </script>", value) ClientScript.RegisterClientScriptBlock(this.GetType(), _STARTUPSCRIPT, startUpScript); }protected void Button2_Click(object sender, EventArgs e){ string value = "Hello World!"; string startUpScript = string.Format("<script language="javascript" type="text/javascript"> function ConfirmIEClose() { if ((window.event.clientX < 0) || (window.event.clientY < 0)) window.event.returnValue = '{0}'; } </script>", value) ClientScript.RegisterClientScriptBlock(this.GetType(), _STARTUPSCRIPT, startUpScript); }
I'm basically just changing the definition of the ConfirmIEClose function.
Can I do a similar thing from within Silverlight?
vincracker
Contributor
3116 points
522 Posts
06-23-2009 2:57 AM |
Yes, You can inject whole javascript function into page using Javascript-Silverlight bridge, here is a sample. For more info on same bing this.