Click here to Skip to main content
15,881,709 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,
i want to store the id of a user controls(ascx) in javascript file
so that i can retrieve that id in aspx page at later stage

how can i do that>?
Posted
Comments
Sergey Alexandrovich Kryukov 5-Jul-11 5:17am    
Id?
--SA

<script>

var id = <%=myControl.ClientId%>

</script>


However, this is not a nice technique. Why not have your js function take the ID as a parameter? Then in the codebehind add your event and use the ClintID there.
 
Share this answer
 
When you build your form, you have to assign an id to the user control that is unique to the page. That id tag is what you use in the code behind to access the user control from code. The client id is only useful on the client side if you wish to manipulate the control in some way from javascript. The only caveat on this is if you are using a control like a Gridview. In those cases you can loop through each of the items from the code behind and then pull out the individually names controls that may exist in your templates. This again would be done by id and not client id so there really should be no purpose for you knowing the client id in the code behind. If there is a valid reason that I am missing, please update the question to explain why you need it.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900