How to get child controls correct id to client side

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,

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 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.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x