Is it possible to call Silverlight code behind methods through an ASPX Page?

I have embedded a Silverlight application in my ASP.NET page and this Silverlight application has two methods.

I want to call those methods through the ASPX page, i.e. my ASPX page has one Button control and when I click this button I want to call one of the Silverlight methods.

Is it possible? How would I do it?


You can use Javascript to make a silverlight method calls.

To permit user to access method of Silverlight from JavaScript, you have to set [ScriptableMember] attribute to that method.

If you want to invoke those methods by ASPX methods/events, you should generate Javascript that invokes the silverlight methods.




public class ScriptableClass
        public void ShowAlertPopup(string message)
            MessageBox.Show(message, "JS Message", MessageBoxButton.OK);


 private void Application_Startup(object sender, StartupEventArgs e)
            this.RootVisual = new MainPage();
            ScriptableClass myScript = new ScriptableClass();
            HtmlPage.RegisterScriptableObject("scriptableClass", myScript);


 <script type="text/javascript">     
        var ctlSLHost = null;
        function onPluginLoaded(sender, args) {
            ctlSLHost = sender.getHost();

        function InvokeSLMethod_ShowAlertPopup() {
        ("Showing alert from JS in SL!");

        <div style="width: 250px; background: lightblue; font-weight: bold;height:30px">
            HTML Part
            <input type="button" value="Invoke SL Method - ShowAlertPopup" 
        onclick="InvokeSLMethod_ShowAlertPopup();" /></div>

 <object data="data:application/x-silverlight-2," type="application/x-silverlight-2"
            width="100%" height="80%">
            <param name="source" value="ClientBin/Silverlight2JSViseVersa.xap" />
            <param name="onError" value="onSilverlightError" />
            <param name="background" value="white" />
            <param name="minRuntimeVersion" value="4.0.50826.0" />
            <param name="autoUpgrade" value="true" />         
            <param name="onLoad" value="onPluginLoaded" />

            <a href= 
        style="text-decoration: none">
                <img src= 
        alt="Get Microsoft Silverlight"
                    style="border-style: none" />

Need Your Help

RoR MongoDB Arrayfield usage

ruby-on-rails arrays mongodb

i'm new to MongoDB and unsure how to use the Array-Field-Type.