1

when i m trying to invoke javascript function which is present in my default.aspx page, it is showing some error --> Failed to Invoke: TalkToJavaScript.

coding in my silverlight page is--

    public MainPage()
    {
        InitializeComponent();
        HtmlPage.RegisterScriptableObject("Page", this);
        HtmlPage.Window.Invoke("TalkToJavaScript", "Hello from Silverlight");

    }
    [ScriptableMember]
    public void UpdateText(string result)
    {
        myTextbox.Text = result;
    }
4
  • 1
    Do you have <param name="enablehtmlaccess" value="true"/> in the HTML declaration of your Silverlight object? Commented Feb 22, 2010 at 5:12
  • no i have not added...under which tag I have to add this , i mean under <body> or <head> Commented Feb 22, 2010 at 5:22
  • 1
    @gabe: If the silverlight app is hosted on the same server as the Default.aspx refered to the default for this value is true anywy. Commented Feb 22, 2010 at 13:24
  • @Piyush: Can you show us some of your Default.aspx, specifically where you define the function TalkToJavascript? Commented Feb 22, 2010 at 13:25

1 Answer 1

1

I would consider using this approach:-

public MainPage() 
{ 
    InitializeComponent(); 
    HtmlPage.RegisterScriptableObject("Page", this); 
    Loaded += (s, args) => {
      HtmlPage.Window.Invoke("TalkToJavaScript", "Hello from Silverlight"); 
    };

} 

I'm not sure why but I'd be uncomfortable calling back into Javascript from a constructor that I know is running in response to an Application_Startup. I'm either being irrational or this is the cause of your problem. Of course currently you aren't showing us the Javascript so you could simply have that messed up.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.