Skip to main content

Microsoft Silverlight

Answered Question how to get the id of the silverlight element in the javascript in separate aspx pageRSS Feed

(0)

bobbby
bobbby

Member

Member

53 points

173 Posts

how to get the id of the silverlight element in the javascript in separate aspx page

i have the silverlight control like this below inside the separate aspx page

<div id="PopupStatus" runat="server">

</div>

<asp:Panel ID="StatusPanel" Style="display: none" Width="600px" runat="server">

<asp:Panel ID="pnlInnerPopup" runat="server" >

<%-- <asp:UpdatePanel ID="upPopUpEvent" runat="server" UpdateMode="Conditional">

<ContentTemplate>--%>

<table border="0" align="center" cellpadding="0" cellspacing="0" width="60%" id="silvertable"

runat="server" >

<tr>

<td valign="top" >

<div id="Div1" style="height: 100%; background-color: #61b7ff;" align="center" runat="server">

<asp:Silverlight ID="Silverlight1" Windowless="true" runat="server" Source="~/ClientBin/silverlightpopup.xap"

HtmlAccess="SameDomain" MinimumVersion="2.0.31005.0" Width="420" Height="200" />

<</div>

</td>

</tr>

</table>

 

i am trying to get the id of the silverlight control using

function showbrand() {

alert("hai");

var control = document.getElementById("<%=Silverlight1.ClientID%>");

//var test = $find('<%=Silverlight1.ClientID%>').value;

alert(control);

 

//control.content.MyControl.Animatepopup();

}

when i am trying to call the method inside code behind is using below statement

 

string popupScript = "<script language='javascript'>showbrand();</script>";

ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "PopupScript", popupScript, false);

 

 

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

Bobby

watabou
watabou

Member

Member

418 points

75 Posts

Answered Question

Re: how to get the id of the silverlight element in the javascript in separate aspx page

 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> 

(If this has answered your question, please click on "mark as answer" on this post. Thank you!)
Hope it helps !
Bastien BESSON

Min-Hong Tang - MSFT
Min-Hong...

Contributor

Contributor

3619 points

412 Posts

Answered Question

Re: how to get the id of the silverlight element in the javascript in separate aspx page

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

 

Min-Hong Tang
Microsoft Online Community Support

Please remember to mark the replies as answers if they help and unmark them if they provide no help.
  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities