none
Pass Data from Silverlight to ASP.NET

    Question

  •  If I have a form in Silverlight and embedded into an ASP.NET page, For example: 

     <body style="height:100%;margin:0;">
        <form id="form1" runat="server" style="height:1000px;">
            <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
            <div  style="height:1000px;">
                <asp:Silverlight ID="Xaml1" runat="server" Source="~/ClientBin/RegressionTool.xap" MinimumVersion="2.0.30523" Width="100%" Height="100%" />
            </div>
        </form>
    </body>

     The above is auto-generated for me to embed the Silverlight client-side into an ASP.NET page, but if I try to access Xaml1 in the code-behind file I can't seem to find a property that lets me access the silverlight controls contained within. Is there a way to get data from the controls and then use/change it in the ASP.NET code behind?

    Thanks for any help!

     

    Monday, July 21, 2008 11:07 AM

Answers

  • You can't access silverlight application from asp.net (except properties of silverlight control), because silverlight runs on client, asp.net - on server. You can put data from silverlight to asp.net and backwards using hidden fields - in sl app put value to hidden fileld on the page and post form to server, get data on server. If you need to send some data to manipulate with sl on client - put data in hidden field and send to client, on client side get and use it with sl control.

    Monday, July 21, 2008 11:54 AM
  • Do you want to access Xaml1 Silverlight control in the .Net Server side code or you want to access it in the page when the page is rendered in the browser?

    On the server side, you can access Xaml1 .net control to set some parameters for that control tag, but you can not access any Silverlight code or controls  because the code is not running on server. The ASPX page is only responsible to write out <object id="Xml1" data="data:application/x-silverlight," type="application/x-silverlight-2-b2" width="100%" height="100%" >...</object> to your page.

    On the client side, you can use JavaScript to access Silverlight code, but the Silverlight code has to be tagged as ScriptMember. see this thread:

    http://silverlight.net/forums/p/14964/49510.aspx#49510

     

     

    Monday, July 21, 2008 11:59 AM

All replies

  • You can't access silverlight application from asp.net (except properties of silverlight control), because silverlight runs on client, asp.net - on server. You can put data from silverlight to asp.net and backwards using hidden fields - in sl app put value to hidden fileld on the page and post form to server, get data on server. If you need to send some data to manipulate with sl on client - put data in hidden field and send to client, on client side get and use it with sl control.

    Monday, July 21, 2008 11:54 AM
  •  This is the kind of answer I expected, although I was hoping something better existed. 

     Thanks!

    Monday, July 21, 2008 11:58 AM
  • Do you want to access Xaml1 Silverlight control in the .Net Server side code or you want to access it in the page when the page is rendered in the browser?

    On the server side, you can access Xaml1 .net control to set some parameters for that control tag, but you can not access any Silverlight code or controls  because the code is not running on server. The ASPX page is only responsible to write out <object id="Xml1" data="data:application/x-silverlight," type="application/x-silverlight-2-b2" width="100%" height="100%" >...</object> to your page.

    On the client side, you can use JavaScript to access Silverlight code, but the Silverlight code has to be tagged as ScriptMember. see this thread:

    http://silverlight.net/forums/p/14964/49510.aspx#49510

     

     

    Monday, July 21, 2008 11:59 AM
  • Can u pls give an example to achieve this. It will be of great help!

    Tuesday, January 27, 2009 2:02 AM
  •  If you want to see an example of accessing Silverlight control from JavaScript, click the link I provided in my last post.

    Tuesday, January 27, 2009 8:51 AM
  • Hi, Did you find the right solution. 

    I am also in need of passing data to asp.net. I have a datagrid in silverlight page and want to export the grid data into PDF. 

    I was thinking to transfer the data from Silverlight to a generic Asp.net handler where I can create PDF using any PDF library.

    Please help me out.

    I am using WCF RIA services and my silverlight project is in SL3. 

    Thanks  

    Wednesday, August 04, 2010 8:33 AM
  • If you already using a WCF RIA service to get the Data to bind to your DataGrid in Silverlight, that means the Data is originally comming from your Server, right?

    Now you want to generate PDF using PDF library on the server, why do you need to send the data from Silverlight back to server? Your service side code can just the call the same service code directly to get the Data then generate the PDF file.




    Wednesday, August 04, 2010 3:56 PM
  • Hi Sladapter, 

    Thanks for the reply, 

    The data is result of complex search queries which is written in Silverlight. 

    Its current version is 3 so I can not directly print the results. Now I was thinking to sending this filtered data back to server and then use this data to print or generate PDF. 

    Please let me know if there is any solution?

    Saturday, August 07, 2010 6:18 AM
  • The data is result of complex search queries which is written in Silverlight. 

    1) You can just send the query back.

    Say the first time you only send the query back to get the data back to display on the screen. When user click the Print button, you can call a WCF print function with the query as parameter. On server side it will get the data using that same query then generate the pdf file.  

    2) If you really want the exact same list (data could change between your first query and 2nd query) to be printed,  you can send the list back via a regular WCF function.  RIA functions seem to have limitations to the input parameter.  That's one thing I don't like RIA, it's too rigid. 

    Saturday, August 07, 2010 9:21 AM
  • Hi ,

    I have a requirement,

    I have a datagrid with some data, when I click on Edit it has to populate the data in Asp.net page with the selected record and when I modify and submit it has to update the sliverlight datagrid.

     

    Can you please help me out with some example.

     

    Thanks in advance,
    Suresh

     

    Wednesday, February 09, 2011 1:51 AM
  • Hi Sladapter,

    Did you find any solution for the query I have posted, can you please find some solution.

    Tuesday, February 15, 2011 5:57 AM
  • Is there a reason you have to use an ASP page instead of Silverlight page to do the Edit?



    Tuesday, February 15, 2011 8:59 AM
  • how to pass data from asp.net to silverlight?

    Monday, June 18, 2012 7:21 AM