Skip to main content
Home Forums Silverlight Programming Report a Silverlight Bug how to get the id of the silverlight element in the javascript in separate aspx page
2 replies. Latest Post by Min-Hong Tang - MSFT on November 2, 2009.
(0)
bobbby
Member
53 points
173 Posts
10-28-2009 8:34 AM |
i have the silverlight control like this below inside the separate aspx page
<ContentTemplate>--
i am trying to get the id of the silverlight control using
alert(
alert(control);
}
when i am trying to call the method inside code behind is using below statement
but the alert statement only displaying the null value i don't know how to get that silverlightcontrolelementid
give some idea to solve this
the same silverlight application aspx page the element id is working fine
but when trying to added the class library as silverlight application in separate asp.net solution
i can't able to get the element id
watabou
418 points
75 Posts
10-28-2009 5:41 PM |
I'm not sure to completely understand your problem, but if you want to access to the silverlight content by Javascript, I recommend you first not to use the asp:Silverlight control and use the object control instead, it will moreover give you really more control about it.
<div id="silverlightControlHost"> <object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%"> <param name="source" value="ClientBin/SilverlightApplication.xap"/> <param name="onError" value="onSilverlightError" /> <param name="background" value="white" /> <param name="minRuntimeVersion" value="3.0.40624.0" /> <param name="autoUpgrade" value="true" /> <a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=3.0.40624.0" style="text-decoration:none"> <img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style:none"/> </a> </object><iframe id="_sl_historyFrame" style="visibility:hidden;height:0px;width:0px;border:0px"></iframe></div>
And then the follow script using jQuery :
<script type="text/javascript"> $(function() { var slControl = $("silverlightControlHost > object"); });</script>
Min-Hong...
Contributor
3584 points
411 Posts
11-02-2009 5:52 AM |
Hi Bobby,
I recommand you to use object element instead of asp:silverlight , that control is deprecated. Then you can use plain client side javascript to get the id of the silverlight plugin and do whatever you want.
There is only a few certains ways you can pass value from asp.net pages. Say querystring, application level variabl, session, etc. To decide which approach to use mainly depends on the scenerio you are dealing with.
There is a link about all the ways to pass value between asp.net pages . You can have a look and decide which one to use.
As to get the exact id of the SilverlightPugin object , you can use approach Watabou mentioned. After you get the value you can pass it using those passing approaches.
Best Regards