views:

71

answers:

3

I'm working with both silverlight and asp mvc. The silverlight application performs a page request, and it works fine (into the test page generated by the VS), but I can't find a way to put it into my view.

MiniSIG

<div id="silverlightControlHost"> 

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


      <param name="source" value="/ClientBin/MiniSIG.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="http://go.microsoft.com/fwlink/?LinkID=149156&amp;v=3.0.40818.0" style="text-decoration:none">
          <img src="http://go.microsoft.com/fwlink/?LinkId=161376" alt="Get Microsoft Silverlight" style="border-style:none"/>
      </a>
    </object>

</div> 

I tried almost everything (from putting the whole thing in the Site.Master page to loading the Silverlight.js from there). Can anywone give me some advice on how should I do this?

My view now looks like:

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <h2>MiniSIG</h2>

    <div id="silverlightControlHost"> 

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


          <param name="source" value="/ClientBin/MiniSIG.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="http://go.microsoft.com/fwlink/?LinkID=149156&amp;v=3.0.40818.0" style="text-decoration:none">
              <img src="http://go.microsoft.com/fwlink/?LinkId=161376" alt="Get Microsoft Silverlight" style="border-style:none"/>
          </a>
        </object>

    </div> 

</asp:Content>

And my Site.Master:

<head runat="server">
    <title><asp:ContentPlaceHolder ID="TitleContent" runat="server" /></title>
    <link href="../../Content/Site.css" rel="stylesheet" type="text/css" />
     <style type="text/css">
    html, body {
        height: 100%;
        overflow: auto;
    }
    body {
        padding: 0;
        margin: 0;
    }
    #silverlightControlHost {
        height: 100%;
        text-align:center;
    }
    </style>
    <script type="text/javascript" src="Silverlight.js"></script>
    <script type="text/javascript">
        function onSilverlightError(sender, args) {
            var appSource = "";
            if (sender != null && sender != 0) {
                appSource = sender.getHost().Source;
            }

            var errorType = args.ErrorType;
            var iErrorCode = args.ErrorCode;

            if (errorType == "ImageError" || errorType == "MediaError") {
                return;
            }

            var errMsg = "Unhandled Error in Silverlight Application " + appSource + "\n";

            errMsg += "Code: " + iErrorCode + "    \n";
            errMsg += "Category: " + errorType + "       \n";
            errMsg += "Message: " + args.ErrorMessage + "     \n";

            if (errorType == "ParserError") {
                errMsg += "File: " + args.xamlFile + "     \n";
                errMsg += "Line: " + args.lineNumber + "     \n";
                errMsg += "Position: " + args.charPosition + "     \n";
            }
            else if (errorType == "RuntimeError") {
                if (args.lineNumber != 0) {
                    errMsg += "Line: " + args.lineNumber + "     \n";
                    errMsg += "Position: " + args.charPosition + "     \n";
                }
                errMsg += "MethodName: " + args.methodName + "     \n";
            }

            throw new Error(errMsg);
        }
    </script>

</head>

I can't see any problem here, the div names are the same.

+2  A: 

One mistake I see is that you should have a forward slash before the ClientBin folder...

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

Also, I'd include this code to ensure Firefox compatibility:

<style type="text/css">     
#silverlightControlHost
{
  height: 100%;
}
</style>

<div id="silverlightControlHost"> 
  <!-- Silverlight object goes here -->
</div> 

(Otherwise the Silverlight app will be collapsed and invisible in Firefox.)

Steve Wortham
A: 

Thanks, it barely worked (worked on Chrome, but still don't work on Firefox). How can I erase the Firefox cache (if this is the problem)? Sorry if it's not a programming question, but it is buging me. I put the <% Response.AddHeader("Pragma", "No-Cache"); %> line in the begining of my Site.Master, and my header looks like:

<style type="text/css">
    html, body {
     height: 100%;
     overflow: auto;
    }
    body {
     padding: 0;
     margin: 0;
    }
    #silverlightControlHost {
     height: 100%;
     text-align:center;
    }
    </style>
    <script type="text/javascript" src="Silverlight.js"></script>
    <script type="text/javascript">
        function onSilverlightError(sender, args) {
            var appSource = "";
            if (sender != null && sender != 0) {
              appSource = sender.getHost().Source;
            }

            var errorType = args.ErrorType;
            var iErrorCode = args.ErrorCode;

            if (errorType == "ImageError" || errorType == "MediaError") {
              return;
            }

            var errMsg = "Unhandled Error in Silverlight Application " +  appSource + "\n" ;

            errMsg += "Code: "+ iErrorCode + "    \n";
            errMsg += "Category: " + errorType + "       \n";
            errMsg += "Message: " + args.ErrorMessage + "     \n";

            if (errorType == "ParserError") {
                errMsg += "File: " + args.xamlFile + "     \n";
                errMsg += "Line: " + args.lineNumber + "     \n";
                errMsg += "Position: " + args.charPosition + "     \n";
            }
            else if (errorType == "RuntimeError") {           
                if (args.lineNumber != 0) {
                    errMsg += "Line: " + args.lineNumber + "     \n";
                    errMsg += "Position: " +  args.charPosition + "     \n";
                }
                errMsg += "MethodName: " + args.methodName + "     \n";
            }

            throw new Error(errMsg);
        }
    </script>

Any advice?

PS: At my browser status field, it shows that my page is trying to reach Microsoft site (which is weird, since I already have the silverlight running, even in firefox).

Bruno
I'm sure it's not the cache. F5 should refresh the HTML (which should do the trick), and Shift+F5 will refresh everything else. So either there's some issue with your particular install of Firefox or there's something else wrong in your markup. If you open up Regex Hero ( http://regexhero.net/tester/ ) in Firefox, does it work? If so, you might find the answer in the HTML of that page.
Steve Wortham
As for the microsoft.com in the status bar, there is an image that points to http://go.microsoft.com/fwlink/?LinkId=108181 for the "Get Silverlight" button.
Steve Wortham
But it doesnt even show this get silverlight button, so, its pointless.
Bruno
The Get Silverlight button should only appear if you don't have Silverlight installed (but it's going to access that URL regardless). I'm still thinking there's something else going on here.
Steve Wortham
Where else could the problem be? I put the style and the script in the header, and at my view page I just put the code inside the div tags as you said above. In the Chrome it works fine, and the default test page works fine on firefox too.
Bruno
You didn't post the full HTML so I'm not sure. Is the div id using the same case as the CSS? It should be `id="silverlightControlHost"`. I ran into this same issue with Regex Hero not showing up in Firefox last year, by the way. Turned out to be a CSS issue.
Steve Wortham
OK, the HTML looks fine to me too. Had you changed the Silverlight app itself? If so you can manually clear that cache within Firefox. Or you can force the browser to download a new version of the XAP file like this... `<param name="source" value="/ClientBin/MiniSIG.xap?ticks=<%= Date.Now.Ticks %>"/>`
Steve Wortham
I get a compilator eror with this code line.
Bruno
I didn't test it... maybe it should be DateTime.Now.Ticks? Or just forget the ASP.NET tags and type some gibberish into the querystring. The idea is that the querystring makes the browser think that it's a different resource than it downloaded last time, and therefore has to get a fresh copy.
Steve Wortham
It didn't work as well.
Bruno
A: 

I solved the problem using half the solution Steve Wortham gave: instead of typing 100%, I typed 480px, which is the size of my Silverlight application, that now works on Firefox too.

Bruno