How do i reload/refresh a silverlight control in javascript?
-
Wednesday, April 22, 2009 9:08 PM
Hi,
I have a html page that contains a couple of silverlight controls. Is there anyway that I can reload/refresh one of these controls from javascript?
Basically, I want to reload the control because I have a textblock in the control that populates with random values when it is loaded. I've tried invoking the method that populates the textblock from javascript, but for some reason, event though it calls the method, the updated text is not rendered. I can't seem to find a solution, so my plan B is to reload the control.
Regards
All Replies
-
Wednesday, April 22, 2009 9:23 PM
Hi,
Stick to your first plan as it should work!
You do not need to refresh the Silverlight object in the page.You should be able to change the value of a TextBlock in Silverlight from JavaScript by using the DOM bridge.
If you need more information on this tell me. -
Wednesday, April 22, 2009 9:27 PM
I've worked it out. Not sure if this it the clean way, but it works. I just set to the source to the source in the javascript function. That forces it to reload:
slCtl.Source = slCtl.Source;
-
Wednesday, April 22, 2009 9:41 PM
The DOM bridge seemed to work fine, except it doesn't render the new value. The javascript successfully calls the scriptable sub below:
<ScriptableMember()> Public Sub LoadPostItText() Dim tiplist(3) As Stringtiplist(0) =
"tip1tiplist(1) =
"tip2"tiplist(2) =
"tip3"tiplist(3) =
"tip4" Dim randomclass As New Random Dim i As Integer = randomclass.Next(0, tiplist.Count - 1) Me.txtTip.Text = tiplist(i) End SubThe sub updates the textblock, but it just doesn't render the updated value. It's as though it's updating a different instance of the control. I don't see how that can be the case though because in the onload event for the control, I call the following javascript function:
var
slCtl = null;function
pluginLoaded(sender) {slCtl = sender.get_element();
}This set slCtl to the element. I then use this in the following javascript function which calls the scriptable sub:
function
load_postit() {slCtl.Content.postit.LoadPostItText();
}
postit is registered in the control's app.xaml.vb as follows:
Private Sub Application_Startup(ByVal o As Object, ByVal e As StartupEventArgs) Handles Me.Startup Me.RootVisual = New Page() Dim smt As Page = New Page()System.Windows.Browser.HtmlPage.RegisterScriptableObject(
"postit", smt) End SubCan you see anything wrong with this (apart from hardcoding etc.)?
Regards,
-
Tuesday, April 28, 2009 3:08 AM
for reload silverlight page by javascript, please check this thread
-
Thursday, August 06, 2009 3:30 AMhi i have the same problem here i sent the data from the javascript and it sent true value but the text of the textblock didn't change and please i need to know the reason or any help thnx in advance
-
Friday, August 21, 2009 12:49 PM
Here is a walkthrough I wrote. It should work well for you and is simple and easy to follow.
-
Monday, August 09, 2010 1:41 AM

