Tags: | Categories: Blog Posted by admin on 8/28/2009 7:46 AM | Comments (3)

With the templates coming out of VS2008 when you create a Silverlight application, a ASP.NET Web project is created for you to test your Silverlight app that adds the control into a ASPX page and a HTML page. Many developers will use the power of ASP.NET for server side processing and add a few ASP.NET controls on the page where the Silverlight control is.

There is when the user will find the problem about mixing up server side controls and Silverlight, the server side controls will cause postbacks that will refresh the Silverlight control. To avoid that problem, the developer may want to use MS ASP.NET AJAX to avoid the server side controls from doing a postback using the UpdatePanel. For this to work there is a simple modification that you need to do at the page where you are hosting the Silverlight control.

First drag and drop the ScriptManager on the page.

image

Second replace the location of the Silverlight.js file from:

<script type="text/javascript" src="Silverlight.js"></script>

 

To be hosted inside the ScriptManager like this:

<asp:ScriptManager ID="ScriptManager1" runat="server">
        <Scripts>
           <asp:ScriptReference Path="Silverlight.js" />
          </Scripts>
         </asp:ScriptManager>

Now all the controls hosted inside the UpdatePanels should work, remember not to add an UpdatePanel to wrap the Silverlight control.

Happy Silverlighting.

Cheers

Al

Follow me in twitter | bookmark me | Subscribe to my feed | Add stats to your blog

Comments

on 8/31/2009 5:51 AM

Pingback from Twitter Trackbacks for Mixing Silverlight and MS ASP.NET AJAX 3.5 in the same web application. : Al Pascual [alpascual.com] on Topsy.com


on 8/31/2009 3:27 PM

Thank you for submitting this cool story - Trackback from DotNetShoutout


on 11/17/2009 5:11 AM

Hi, thanks for the explanation.  However, I'm still getting a refresh on my SL application everytime I hit the button on the asp.net form.  Here's my code:


<form id="form1" runat="server"


<asp:ScriptManager ID="ScriptManager1" runat="server"><Scripts><asp:ScriptReference Path="Silverlight.js" /> </Scripts>


</asp:ScriptManager>


<asp:UpdatePanel ID="UpdatePanel1" runat="server"


<ContentTemplate>


<asp:Button Text="asdasd"  runat="server" onclick="Unnamed1_Click" />


<div id="silverlightControlHost">


<object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%">


<param name="source" value="ClientBin/SilverlightApplication1.xap"/>


      <param name="onError" value="onSilverlightError" />


      <param name="background" value="white" />


      <param name="minRuntimeVersion" value="3.0.40818.0" />


      <param name="autoUpgrade" value="true" />


      <a href="go.microsoft.com/.../ style="text-decoration:none">


        <img src="go.microsoft.com/fwlink/?LinkId=108181" 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>


        </ContentTemplate>


       </asp:UpdatePanel>


</form>


Comments are closed