interfacing asp.net controls from silverlight 3

Last post 10-24-2009 8:39 AM by snedzad. 1 replies.

Sort Posts:

  • interfacing asp.net controls from silverlight 3

    10-23-2009, 10:44 PM
    • Member
      point Member
    • willlennon
    • Member since 10-24-2009, 2:23 AM
    • Posts 1

    I'm learning asp.net and silverlight 3 and I have a stupid beginner question.

    I want my silverlight application to be take inputs from my asp.net web page, and pass data back to the web page.

    I'd love to see some example code that passes data back and forth.

    ie, pass strings from a textbox control to silverlight and have silverlight later update a label.

    The few examples I've found deal with silverlight 2, the deprecated asp:silverlight control, and DOM manipulation.

    From silverlight I can find a label on my web page named 'MyLabel' by this hack:

    tb2 = HtmlPage.Document.GetElementById("ctl00_Right_MyLabel");

    .. but I cannot set the value, ie this does nothing:

    tb2.SetProperty("value","changed by silverlight");

     

    Any pointers appreciated.  Thanks in advance!

     

     

  • Re: interfacing asp.net controls from silverlight 3

    10-24-2009, 8:39 AM
    • Member
      4 point Member
    • snedzad
    • Member since 10-24-2009, 6:38 AM
    • Posts 2

    Hi,

    Silverlight is a client technology and you can modify asp.net web page (to be more precise, rendered HTML output page) via Javascript.

    Moreover, you can pass initialization parameters from a web page to Silverlight object.

    <object data="data:application/x-silverlight," type="application/x-silverlight-2" width="100%" height="100%">
            <param name="source" value="ClientBin/InitParams.xap"/>
            <param name="onerror" value="onSilverlightError" />
            <param name="background" value="white" />
            <param name="initParams" value="your init parameters" />

    In your example, you should try to modify "innerHTML" property of label element.


    void Button1_Click(object sender, EventArgs e)
    {
     
        // Change label innerHTML property value
        HtmlElement label1 = HtmlPage.Document.GetElementById("label1");
        label1.SetProperty("innerHTML","changed by silverlight");
    }



Page 1 of 1 (2 items)