Categories: Silverlight 2 Tips Posted on 6/30/2009 10:36 AM by Ryan Shelby  Feedback (0)

Last week I created a Silverlight 2 Control called the Print Friendly Datagrid Control

 

I uploaded the newly published folder "PrintFriendly" to the root of rshelby.com, but when I tried to open the page it was blank.  I took a look at the page errors and discovered there were [3] 'Sys' is undefined errors as shown in the image below.

 

 


Using Fiddler I ran the page again and discovered [3] 500 page results, all leading to URL /ScriptResource.axd.

 


Remembering the Silverlight control was not located in the root of rshelby.com, I changed the ScriptManger in the ASPX page to include ScriptPath="~/PrintFriendly".

 

I ran the page again and I could now see the problem.  The system was looking for 3 javacript files called MicrosoftAjaxWebForms.js, SilverlightControl.js and MicrosoftAjax.js.  

 


To make a long story short, I found the 3 javascript files and placed them into a folder called "scripts" inside my Silverlight Project.

 

Then I added the 3 ScriptReferences to the ScriptManager as shown below.  In my case, each file path lead to "~/PrintFriendly/scripts/"

 

    1  <asp:ScriptManager ID="ScriptManager1" runat="server">    
    2         <Scripts>           
    3             <asp:ScriptReference Name="MicrosoftAjax.js" Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" Path="~/SilverlightProject/scripts/MicrosoftAjax.js" />
    4             <asp:ScriptReference Name="SilverlightControl.js" Assembly="System.Web.Silverlight, Version=2.0.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" Path="~/SilverlightProject/scripts/SilverlightControl.js" />
    5             <asp:ScriptReference Name="MicrosoftAjaxWebForms.js" Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" Path="~/SilverlightProject/scripts/MicrosoftAjaxWebForms.js" />
    6          </Scripts>
    7   </asp:ScriptManager>

 


In addition to the 3 javascripts above, I also added MicrosoftAjax.debug.js, MicrosoftAjaxWebForms.debug.js and SilverlightControl.debug.js

 

scripts.zip (94.30 kb)


One other problem I received before this was related to the ASP TagPrefix [at the top of my ASPX page] for the registered assembly "System.Web.Silverlight".

 

I was able to fix this issue by adding the System.Web.Silverlight.dll to my project's bin folder, then deleting and re-adding the assembly to the project's references.

 


Taking it one step further, I removed the TagPrefix from the top of my ASPX page and then added it as an assembly inside the Web.Config file of the Silverlight Project [as shown below].

 



Future Changes:

Although doing everything above allows me to add new Silverlight Website Projects to my existing ASP.NET website, it's kind of a pain to have to do this every time.  For now I did it this way because I didn't want to mess around with the existing Blog.NET software.

 

In the future I plan to move the Scripts folder and everything else related to my PrintFriendly Silverlight project so it works at the root of rshelby.com.  Then i won't have to do this each time I add a new Silverlight Website or Project.

 

Send Feedback





biuquote
  • Comment
  • Preview
Loading