How to get child controls correct id to client side

[亡魂溺海] 提交于 2019-12-20 02:54:37

问题


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.

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,


回答1:


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

<%=txtControl.ClientID%>

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

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

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



来源:https://stackoverflow.com/questions/2177337/how-to-get-child-controls-correct-id-to-client-side

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!