So I have a Silverlight control that I've added to an ASP.NET Web Forms page using the ActiveX object notation like so:
<object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="500" height="48">
<param name="source" value="/ClientBin/FileUpload.xap?t=<%=DateTime.Now.ToUniversalTime() %>"/>
<param name="onError" value="onSilverlightError" />
<param name="background" value="white" />
<param name="minRuntimeVersion" value="3.0.40818.0" />
<param name="autoUpgrade" value="true" />
<asp:Literal ID="SilverlightInitParams" runat="server" />
<a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=3.0.40818.0" style="text-decoration:none">
<img src="https://go.microsoft.com/fwlink/?LinkId=161376" alt="Get Microsoft Silverlight" style="border-style:none"/>
</a>
</object>
Within the control, there's a button. When the button is clicked, I'd like a JavaScript script to be called. To see if I can get it to work, it should call a JavaScript function that definitely does exist. However, nothing happens.
Here's what the Silverlight code looks like:
public partial class FileUploadControl : UserControl
{
...
public FileUploadControl(IDictionary<string,string> parameters)
{
...
HtmlPage.RegisterScriptableObject("Page", this);
InitializeComponent();
}
private void chooseFileButton_Click(object sender, RoutedEventArgs e)
{
HtmlPage.Window.Invoke("showStatus");
...
}
...
}
Here's the JavaScript method:
function showStatus() {
alert('Test from Silverlight.');
}
Any ideas?