Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6353171
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T22:21:53+00:00 2026-05-24T22:21:53+00:00

We are planning to use Silverlight MVVM application in Dynamics 2011 for few custom

  • 0

We are planning to use Silverlight MVVM application in Dynamics 2011 for few custom features. We also want to have consistent looks for whole application for both Dynamics and Silverlight modules. That’s why we are creating web resource to host this Silverlight application inside CRM.

Now problem is we need to create “Save”, “Edit” etc buttons in Ribbon, which in-turn behaves like buttons inside Silverlight module. Following are important questions

  1. Can we create such buttons in Ribbon to access methods inside View Model of Silverlight application hosted using “Web resource”. These methods will also have to access data changes done by user in Silverlight Views.

  2. Is there any other better way to handle such situation

Thanks,

Nilesh

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T22:21:54+00:00Added an answer on May 24, 2026 at 10:21 pm

    Finally I’ve successfully called the function inside C# code of Silverlight application from Ribbon button click.

    Here is the screenshot of final output.

    OutPut

    Here is what PoC is doing

    1. There is Silverlight application hosted in CRM on custom area-subarea. This in-turn needs two web resources
    2. There is Custom button added in Ribbon
    3. Third web resource is hosting JavaScript function
    4. On click of Custom Button on CRM Ribbon function in JavaScript web resource is called which in-turn calls the method in C# code of Silverlight application. String input is passed to this method
    5. C# method is converting the input string to upper case and returning it.
    6. Finally alert is displayed with upper case string.

    Here are the details to create the PoC

    1. Created new solution in CRM
    2. Created new Area and Sub-Area for this PoC by editing Site Map XML. Here is the XML added in customizations.xml.

    3. Added custom button in Application Ribbon. Here is the updated XML for Ribbon

      Sequence=”101″>

    4. Created Silverlight Application. Here is important C# code.

    Note
    System.Windows.Browser.HtmlPage.RegisterScriptableObject(“SilverlightCode”,
    this); and [ScriptableMember]

    public partial class MainPage : UserControl
        {
            public MainPage()
            {
                InitializeComponent();
                System.Windows.Browser.HtmlPage.RegisterScriptableObject("SilverlightCode", this);                                
            }
    
            // After the Frame navigates, ensure the HyperlinkButton representing the current page is selected
            private void ContentFrame_Navigated(object sender, NavigationEventArgs e)
            {
                foreach (UIElement child in LinksStackPanel.Children)
                {
                    HyperlinkButton hb = child as HyperlinkButton;
                    if (hb != null && hb.NavigateUri != null)
                    {
                        if (hb.NavigateUri.ToString().Equals(e.Uri.ToString()))
                        {
                            VisualStateManager.GoToState(hb, "ActiveLink", true);
                        }
                        else
                        {
                            VisualStateManager.GoToState(hb, "InactiveLink", true);
                        }
                    }
                }
            }
    
            // If an error occurs during navigation, show an error window
            private void ContentFrame_NavigationFailed(object sender, NavigationFailedEventArgs e)
            {
                e.Handled = true;
                ChildWindow errorWin = new ErrorWindow(e.Uri);
                errorWin.Show();
            }
    
            private void button1_Click(object sender, RoutedEventArgs e)
            {
                MessageBox.Show(CustomMethod("Silverlight Button Clicked !"));
            }
    
            //This method will be called from JavaScript on click of Ribbon Button
            //This method needs to be Public
            [ScriptableMember]
            public string CustomMethod(string message = "")
            {
                //MessageBox.Show(message, "Message", MessageBoxButton.OK);
                return message.ToUpper();
            }
        }
    

    SLCode

    Here is important HTML code.

    Note the <object id="SLFromJS"

    <body>
        <form id="form1" runat="server" style="height:100%">
        <div id="silverlightControlHost">
            <object id="SLFromJS" data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%">
      <param name="source" value="ClientBin/RibbonPoC.xap"/>
      <param name="onError" value="onSilverlightError" />
      <param name="background" value="white" />
      <param name="minRuntimeVersion" value="4.0.50401.0" />
      <param name="autoUpgrade" value="true" />
      <a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=4.0.50401.0" style="text-decoration:none">
       <img src="http://go.microsoft.com/fwlink/?LinkId=161376" alt="Get Microsoft Silverlight" style="border-style:none"/>
      </a>
        </object><iframe id="_sl_historyFrame" style="visibility:hidden;height:0px;width:0px;border:0px"></iframe></div>
        </form>
    </body>
    
    1. Hosted Silverlight Application in CRM. For this we need to create two web resources – one to host HTML and second for XAP.

    2. Created one more web resource to host JavaScript function. Developer tools (F12) in IE 8 helped me to find exact location of my Silverlight Object (SLFromJS) in HTML DOM. Here is the JavaScript –

    Note window.frames[‘contentIFrame’].document.forms[‘form1’].SLFromJS;

    function CallSilverlightMethod(sender) {
        alert('Inside JS1!');
        var slc = window.frames['contentIFrame'].document.forms['form1'].SLFromJS;
        alert('Inside JS2!');
        if (slc != null) {
            alert('Inside if!');
            alert(slc.Content.SilverlightCode.CustomMethod('Msg From JavaScript'));
            alert('Going out of if!');
        }
        alert('Out of if!');
    }
    

    My CRM solution looks like following now

    CRMSolu

    1. Done! Now test the work by opening link of HTML web resource.

    Thanks to following blog posts which I referred.

    http://www.a2zmenu.com/Blogs/Silverlight/Calling-Silverlight-Method-from-JavaScript.aspx

    accessing a form that is in an iframe

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am planning to use coverflow control in my Silverlight application, but I am
I was planning to use url routing for a Web Forms application. But, after
We're planning to use standard ASP.NET user authentication for our application. However, by default
I'm in the process of planning an application that would make use of the
We are planning to develop a web based application using Silverlight 2.0. The application
I am planning to use Silverlight control for bing map. It will be used
I am planning to use Hadoop on EC2. Since we have to pay per
I'm planning to use Python to develop a web application. Anybody has any idea
I have to do my final year project and I'm planning to use a
I am planning to use jquery in Rails instead of prototype. I am not

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.