eZine4i.com - Free Articles Directory From Search4i Network
   
   
 
 

ARTICLE CATEGORIES

SEARCH4i NETWORK

Follow Me on Twiter

ADVERTISEMENTS

 

TOP 5 AUTHORS

Alan Smith 532
Angelo Everton 307
Kaye Z. Marks 291
Ashish Pandey 257
Julia Bennet 256

How to call Javascript functions from Silverlight code ?

addthis
     
Author:

Chetas

Category: HomearrowProgramming
Summary:

One of the advantages of Silverlight is, it has access to the Html document of the web page in which it is hosted. This enables Silverlight to access HTML elements in the page and also call Javascript methods.

Article:
The following steps shows how to call a Javascript method from Silverlight.

Open the ASP.NET or HTML page which hosts the Silverlight control. Add the Javascript method as shown below:


<script language="javascript"≫
function SayHello()
{
alert("Hello from JavaScript, invoked by Silverlight");
}
</script>


Now, open your XAML control file and add a button control as shown below:


<Grid x:Name="LayoutRoot" Background="White">
<Button x:Name="btnSayHello" Content="Say Hello"
Click="btnSayHello_Click"></Button>
</Grid>


Go to the code behind file for the XAML Page and add the event handler for the button click event:


private void btnSayHello_Click(object sender, RoutedEventArgs e)
{
HtmlPage.Window.Invoke("SayHello");
}


In order to use the HtmlPage class, you need to include the System.Windows.Browser


using System.Windows.Browser;

You are done. Run your Silverlight application and see. When you click on the button in the Silverlight control, you can see the popup message from the Javascript function.
Source: Free Articles from ezine4i.com
About Author: emailverified

Rate It:
     

TOP

RELATED ARTICLES

bullet Project Scheduling – The Central Piece Of A Project Management Software
By:Ioan Lucian Category:Programming
bullet Why hire PHP Development Company for web development projects
By:Chris Miller Category:Programming
bullet Package Software with InstallAware Studio for Windows Installer
By:Candice Jones Category:Programming
bullet Package Software with a Free Installer
By:Candice Jones Category:Programming
bullet What to look before hiring iPhone Developer from reliable company?
By:dave Category:Programming
bullet Penny Auction Strategy for New Bidders
By:David John Category:Programming
bullet Customization In Iphone Application Development
By:Dharmraj Singh Category:Programming
bullet Driving Web-based Commerce with Magento Development
By:Jerome Smith Category:Programming
bullet Hire PHP Developers to enhance your online business
By:vivekcis Category:Programming
bullet The Zend Developer Pulse Survey – Expected Trends In The Technology In 2012
By:Chris Miller Category:Programming