I have default.aspx page contains a button and silverlight control like <asp:silverlight id=".." source="path of xap file">
I have silverlight xap file, on click of this button in default.aspx, I want
that its initparams change and xap file reload or refresh, this should be from javascript i.e no postback should be there.
Can anyone specify the solution.
Sachin Mukhija
"Please Mark as answer if answer is correct".
I am not aware of any method to force a silverlight to reload without a postback. You can make some of the silverlight app's functions callable by javascript.
skm.software...
Member
236 Points
298 Posts
refresh xap file from javascript
Dec 10, 2008 01:21 PM | LINK
Hi all
I have default.aspx page contains a button and silverlight control like <asp:silverlight id=".." source="path of xap file">
I have silverlight xap file, on click of this button in default.aspx, I want
that its initparams change and xap file reload or refresh, this should be from javascript i.e no postback should be there.
Can anyone specify the solution.
"Please Mark as answer if answer is correct".
Ken Tucker
All-Star
23246 Points
3532 Posts
Re: refresh xap file from javascript
Dec 10, 2008 04:47 PM | LINK
I am not aware of any method to force a silverlight to reload without a postback. You can make some of the silverlight app's functions callable by javascript.
http://msdn.microsoft.com/en-us/library/cc221414(VS.95).aspx
But the html bridge allows silverlight to interact with the html page it is hosted on
http://msdn.microsoft.com/en-us/library/cc645076(VS.95).aspxSpace Coast .Net User Group
Amanda Wang...
All-Star
17236 Points
1466 Posts
Microsoft
Re: refresh xap file from javascript
Dec 15, 2008 07:40 AM | LINK
Hi,
You can try to place the silverlight control into a UpdatePanel to avoid the whole page postback.
for example:
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Silverlight ID="Xaml1" runat="server" Source="~/ClientBin/testChat.xap" InitParameters="user=" MinimumVersion="2.0.30923.0" Width="100%" Height="100%" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Button1" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
the code behind of the button click event:
protected void Button1_Click(object sender, EventArgs e)
{
this.Xaml1.InitParameters = "user=susan";
}
Microsoft Online Community Support
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
MarkMonster
Star
7590 Points
1497 Posts
Re: refresh xap file from javascript
Dec 22, 2008 02:21 PM | LINK
I created a blogpost on the solution here:
The quick solution is as follows.
A Javascript function to refresh the silverlight HostElement.
function CreateSilverlight(hostElement, source, initParams) {
var pluginId = hostElement.id + "PluginId";
hostElement.innerHTML = Silverlight.createObject(source,
null, pluginId,
{
width: "200", height: "50",
background: "white", alt: "<!--Silverlight 2.not installed-->",
version: "2.0.31005.0", autoUpgrade: true
},
{ onError: onSLError, onLoad: onSLLoad },
initParams, hostElement.id);
}
The inital load is from the window.load:
window.onload = function() {
CreateSilverlight(silverlightControlHost, "ClientBin/MM.Silverlight.Experiments2.SUI.xap", "param1=value1,param2=value2");
}
The full html looks as follows:
This solution can also be used from within Silverlight. You can call the javascript function very easily from Silverlight as follows:
HtmlPage.Window.Eval(string.Format(
I hope this helps you out more.@"CreateSilverlight(silverlightControlHost,
'ClientBin/MM.Silverlight.Experiments2.SUI.xap',
'currenttime={0},otherparam=othervalue');", DateTime.Now));
Mark Monster
Blog
Silverlight and Expression Insiders UG
Dont forget to click "Mark as Answer" on the post that helped you.