如何获得子控件正确的ID给客户端 [英] How to get child controls correct id to client side

查看:76
本文介绍了如何获得子控件正确的ID给客户端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的ASP.NET和不使用任何ASP.NET的AJAX框架。
现在我试图更新在网格中的文本框和下拉菜单中的内容使用(经典的JavaScript方法)AJAX控件在客户端单元。但我现在面临的问题是,控件(文本框,下拉菜单),我想,当由用户pfixed客户端获取$ P $呈现更新控件ID和行ID。


因此,它变得像 UserContro_row_no_controlId

有了这个就变得很难保持在客户端跟踪控制的ID更新它们。

I am working on ASP.NET and not using any ASP.NET's AJAX framework.
Now I am trying to update the contents of the textboxes and dropdowns in the Grid controls cell on client side using (classic JavaScript way)AJAX. But problem I am facing is that controls (textbox, dropdown) which I would like to update when rendered on the client side get prefixed by the User Controls id and row ids.

So it becomes like UserContro_row_no_controlId.

With this it is becoming difficult to keep track of controls ids on the client side to update them.

请让我知道如何可以简化?

我们可以得到究竟会pfixed当它在客户端呈现给控制$ P $?

有什么好方法ID来客户端?

我一直在使用control.clientId尝试,但它给我的只有 _controlId 的一部分,而不是 UserContro_row_no 的一部分。

感谢所有,

Please let me know how this can be simplified?
Can we get what exactly will be prefixed to control when it’s rendered on client side?
What is good way to get ID to client side ?

I have tried using control.clientId but it’s giving me only _controlId part not the UserContro_row_no part.
Thanks all,

推荐答案

如果你想在同一控制/页面控件的ID,你能做到这一点是这样的:

If you want the id of a control in the same control/page you can do that this way:

<%=txtControl.ClientID%>

如果你想有一个用户控件里的控件的ID,你可以做这样的:

If you want the id of a control inside a usercontrol you can do that like this:

<%=userControl.FindControl("txtControl").ClientID%>

在哪里txtControl为控制和用户控件的服务器ID是用户控件的服务器ID。

Where "txtControl" is the server id of the control and "userControl" is the server id of the usercontrol.

这篇关于如何获得子控件正确的ID给客户端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆