Skip to main content

Microsoft Silverlight

Answered Question Changing Javascript Function definition from SilverlightRSS Feed

(0)

misterken
misterken

Member

Member

14 points

31 Posts

Changing Javascript Function definition from Silverlight

 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
vincracker

Contributor

Contributor

3116 points

522 Posts

Answered Question

Re: Changing Javascript Function definition from Silverlight

Yes, You can inject whole javascript function into page using Javascript-Silverlight bridge, here is a sample. For more info on same bing this.
 

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities