JavaScript-based Content Not Displaying

2 posts, 0 answers
  1. Lee Sauer
    Lee Sauer avatar
    6 posts
    Member since:
    Dec 2009

    Posted 25 May 2010 Link to this post

    Greetings,

    We have an application that uses a SitePal talking avatar in our Asp.NET application that we wish to use in a Silverlight application.  In Asp.NET, we use the following code to invoke the Avatar:

     

    <div class="rowPanel" style="text-align: left;">

     

     

    <script language="JavaScript" type="text/javascript" src="https://vhost.oddcast.com/vhost_embed_functions_v2.php?acc=1460967&js=1"></script>

     

     

    <script language="JavaScript" type="text/javascript">AC_VHost_Embed(1460967, 300, 400, '', 1, 1, 1986041, 0, 1, 0, '4627b06cee4c591411238bee32e628f3', 9);</script>

     

     

    <script language="javascript" type="text/javascript">

     

     

    function vh_sceneLoaded() {

     

    sayText(

    "The Avatar Speaks.", 4, 1, 2);

     

    sayText(

    "The Avatar Speaks Again. ", 4, 1, 2);

     

    }

     

    </script>

     

     

    </div>

    I put the same calls into a Silverlight page using the HTMLPlaceholder control with the following code in my code behind page:

     

    namespace

     

     

    TestHTMLPlaceholder {

     

     

     

    public partial class MainPage : UserControl {

     

     

     

    public MainPage() {

     

    InitializeComponent();

    phHtml.HtmlSource =

     

     

    "<div> This is plain text </div> " +

     

     

     

    "<div> " +

     

     

     

    " <script language=" +

     

     

     

    "\"JavaScript\"" +

     

     

     

    " type=" +

     

     

     

    "\"text/javascript\"" +

     

     

     

    " src=" +

     

     

     

    "\"https://vhost.oddcast.com/vhost_embed_functions_v2.php?acc=1460967&js=1\">" +

     

     

     

    " </script> " +

     

     

     

    " <script language=" +

     

     

     

    "\"JavaScript\"" +

     

     

     

    " type=" +

     

     

     

    "\"text/javascript\">" +

     

     

     

    "AC_VHost_Embed(1460967, 300, 400, '', 1, 1, 1986041, 0, 1, 0, '4627b06cee4c591411238bee32e628f3', 9);</script> " +

     

     

     

    " <script language=" +

     

     

     

    "\"javascript\"" +

     

     

     

    " type=" +

     

     

     

    "\"text/javascript\">" +

     

     

     

    " function vh_sceneLoaded() { " +

     

     

     

    " sayText(" +

     

     

     

    "\"The Avatar Speaks.\"" +

     

     

     

    ", 4, 1, 2); " +

     

     

     

    " sayText(" +

     

     

     

    "\"The Avatar Speaks Again. \"" +

     

     

     

    ", 4, 1, 2); " +

     

     

     

    " } " +

     

     

     

    " </script> " +

     

     

     

    "</div> ";

     

    }

    }

    }

    When I run this, the first <div> (with the plain literal text) displays, so I know I am correctly calling the control, but the second <div> with the javascript calls to invoke the avatar are not displayed.

    Is there a limitation on the use of the HTMLPlaceholder control that I don't understand, or do I have a subtle error in the way I've parsed the code to get the explicit double quotes that I missed?

    Thanks for your help.

    Lee Sauer

  2. Valentin.Stoychev
    Admin
    Valentin.Stoychev avatar
    2198 posts

    Posted 27 May 2010 Link to this post

    Hello Lee Sauer,

    This is expected behavior. It happens due to the fact that we are setting the html byusing the innerHtml property of the javasctipt elements on the page. When added this way the script is not executed.

    What you can do is to add the html and then to execute the Javascript by using the HtmlBridge. You can read more about that here:
    http://blogs.microsoft.co.il/blogs/alex_golesh/archive/2008/12/04/silverlight-tip-how-to-inject-and-execute-javascript-function-s-on-the-fly-from-silverlight.aspx

    This article also maybe of help:
    http://www.silverlight.net/learn/quickstarts/htmlbridge/#accessing_the_html_dom_from_managed_code

    Greetings,
    Valentin.Stoychev
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. DevCraft banner
Back to Top