views:

29

answers:

1

Hi i have an ASP.Net application and from one page i have to redirect to silverlight page, i am new to silverlight so i have two question

  1. Can i add silverlight page in asp.net app or i will have to add silverlight application in asp.net solution.

  2. How to redirect from asp.net page to silver.(i want to pass some data from asp.net to silver light)

+2  A: 

To communicate between a Silverlight control and javascript in an ASP.net page you can use the HTML bridge. Essentially this allows you call specially marked methods in your Silverlight control as well call javascript routines from Silverlight.

Marking a Silverlight method or attribute as accessible to javascript:

   public partial class Page : UserControl
    {

    void Page_Loaded(object sender, System.Windows.RoutedEventArgs e)
    {
        // Register this object in the page as Scriptable
        // so it can be accessed from within JavaScript
       HtmlPage.RegisterScriptableObject("Page", page);
    }

    [ScriptableMember]
    public string HelloFromSilverlight()
    {
        return "Hello";
    }

        [ScriptableMemberAttribute]
        public int SomeValue
        {
            get 
            {   return _someValue;}
        }

}

Calling the Silverlight method from javascript:

        // Get a reference to the actual Silverlight
        // plugin element within the page
        var plugin = pluginObject.get_element();

        // Call the HelloFromSilverlight method of our Silverlight object
        var text = plugin.Content.Page.HelloFromSilverlight();

Also see other examples:

  1. http://www.dotnetspider.com/resources/36450-How-work-with-HTML-DOM-SIlverlight.aspx
  2. http://geekswithblogs.net/PeterTweed/archive/2009/08/08/html-bridge---silverlight-javascript-interop.aspx
BrokenGlass