locked
Silverlight Usercontrol not loading in the asp.net user control RRS feed

  • Question

  • Hello,

            I have created a silverlight project in Silverlight 3. I have a asp.net usercontrol and I am embedding the silverlight user control in the asp.net usercontrol. When I add the .net usercontrol in a simple aspx page it works fine for  me. But when I add the same usercontrol to the aspx page which inherits base page for its properties the Silverlight control does not display. What can be the problem? Anyone please help it's critical.

    Thank You

    Tuesday, January 26, 2010 9:47 AM

Answers

  • Hi,

    Have you checked all the things shamrat231 has mentioned?

    If you use a relative url for Silverlight object source property like below:

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

    then you need to make make sure the path is reachable from where your aspx page resides. For example, when you put your UserControl in Default.aspx, the Silverlight application is showing, but when you put the same UserControl in Pages/Page.aspx, the Silverlight application will not be showing because the relative path is not reachable from Pages folder.

    Please check it and correct me if I misunderstand you, thanks.

    Thursday, January 28, 2010 2:06 AM

All replies

  • Couple of things could be checked.

    1. In the view source of that page if this are included on that page

        <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" mce_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>

    2. and also silverlight.js pointed to the right place. src="Silverlight.js" mce_src="Silverlight.js" maynot work if the page is not in the root.

    3. If the path is correcly pointed to the xap file. value="ClientBin/Personalization.xap" willnot work if page is not in root so modify accordingly for both silverlight.js and .xap

    <object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%">
        <param name="source" value="ClientBin/Personalization.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&v=3.0.40818.0" style="text-decoration:none">
          <img src="http://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>

    Sharker

    Tuesday, January 26, 2010 10:30 AM
  • My Silverlight is added in the .net usercontrol the .ascx page and this .net user control I am using in a screen .aspx page. It works fine when I use it in simple aspx page but when I use it in my solution it is not showing th Silverlight usercontrol.

    Tuesday, January 26, 2010 11:43 AM
  • Hi,

    Have you checked all the things shamrat231 has mentioned?

    If you use a relative url for Silverlight object source property like below:

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

    then you need to make make sure the path is reachable from where your aspx page resides. For example, when you put your UserControl in Default.aspx, the Silverlight application is showing, but when you put the same UserControl in Pages/Page.aspx, the Silverlight application will not be showing because the relative path is not reachable from Pages folder.

    Please check it and correct me if I misunderstand you, thanks.

    Thursday, January 28, 2010 2:06 AM