Skip to main content
Home Forums Silverlight Programming Programming with JavaScript Get silverlight html container
3 replies. Latest Post by pbrooks on June 10, 2009.
(0)
frantise...
Member
0 points
3 Posts
06-09-2009 9:11 AM |
Hi,
is there any possible way to get id of silverlight html container?
In my aspx page i have:
1 <asp:Content ID="Content2" ContentPlaceHolderID="CphMainContent" runat="server"> 2 <asp:Silverlight ID="Silverlight1" runat="server" Source="Silverlight/Komix.RSP.Application.Designer.xap" MinimumVersion="3.0.40307.0" Width="1280" Height="768" /> 3 </asp:Content>
But in final html source code is id of silverlight element something like 'ctl00_CphMainContent_Silverlight1_parent'.
And in my silverlight app i need to get dynamically id of this element.
Can someone help me?
pbrooks
Contributor
2671 points
355 Posts
06-09-2009 1:52 PM |
Personally, I would recommend using the object tag to render your Silverlight plugin instead of the server-side ASP.NET tag. You have more control this way. If you must use the ASP.NET server-side tag, you could query the object tag using jQuery. Something like this would probably suffice:
....<div id="silverlightControlHost"> <object data="data:application/x-silverlight-2," ........
<script type="text/javascript"> $(function() { var slControl = $("silverlightControlHost > object"); });</script>
Or if you just wanted the surrounding div, you could do something like this:
<script type="text/javascript"> $(function() { var slContainer = $("silverlightControlHost"); });</script>
06-10-2009 8:04 AM |
Thanks for suggestion, but i realy need to get id of silverlight html container in SL code.
06-10-2009 8:28 AM |
If you only have one object tag on your page, you could use the following jQuery code to obtain the id of the html container and then store it off in a hidden field:
Html:
<input type="hidden" id="hostId" />
JS: var hostId = $("object").parent().attr('id');$("#hostId").val(hostId);
Then, if you need this value in your SL app, you could then use HTML DOM interop to retrieve the value.
Silverlight C#:
string hostId = HtmlPage.Document.GetElementById("hostId").GetAttribute("value");
If you have more than one object tag, you would simply need to modify the jQuery selector code to pick the one you need.