简体   繁体   English

在JavaScript中的Usercontrol中获取控件的客户端ID

[英]Get Client Id of a control inside Usercontrol in javascript

我有一个带有网格的用户控件,我想从javascript获取网格的客户端ID,有什么办法吗?

You could print out the clientid to the page into a javascript variable. 您可以将页面的clientid打印到javascript变量中。

var userControlID = '<%=userControl.ClientID %>';

In your case if you want the id of the grid. 在您的情况下,如果您想要网格的ID。 Something like this: 像这样:

<asp:UserControl>

<script type="text/javascript">
   var gridID = '<%=myGrid.ClientID%>';
</script>

<asp:GridView id="myGrid" runat="server" >
//content here
</asp:GridView>

</asp:UserControl>

This javascript variable will be available in the global context of the page once it has loaded. 该javascript变量加载后将在页面的全局上下文中可用。

This way 这条路

<script type="text/javascript">
   var id = '<%=gv.ClientID%>';
</script>
...
<asp:GridView id="gv" runat="server" />
...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM