Click here to Skip to main content
15,898,010 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
In below btnBook1 is a server button control id. just i want to access client id of this button.btnBook1 exists dynamically.so when button does not exists then this line of code return error.please provide a way so i can access client id of control.

var str = jquery("#<%=btnBook1.ClientID%>").attr("id").toString();


Please provide solution as soon as possible.
thanks in advance
Posted
Comments
Sergey Alexandrovich Kryukov 11-Feb-13 3:56am    
Incredible!
—SA

Try this

C#
<%=(this.FindControl("btnBook1") == null) ? "" : this.FindControl("btnBook1").ClientID%>
 
Share this answer
 
v2
Comments
Vandana_Pathak 11-Feb-13 4:13am    
Not work...Error did not return but still i did not access client id.
Irbaz Haider Hashmi 11-Feb-13 4:19am    
The control must be on the page to get the ID. Above code will return empty string if it doesn't find that control on page and client id if it finds that. I am thinking you scenario is much complex to this. Tell me more details about it or try to adjust it according to your requirements.
Vandana_Pathak 11-Feb-13 4:26am    
Thanks...actually when get the control in page then above code return object[object] in place or ct_100 like id.
Your code is funny, because you are trying to find id via already id, even if it did not return error. Isn't it obvious? If button does not exist, what do you want? It should return error. Well wrap this line in try-catch, but better rethink your general design of your code…

—SA
 
Share this answer
 
Comments
Vandana_Pathak 11-Feb-13 4:18am    
server control id and client id both are different meaning....so its not funny code
Sergey Alexandrovich Kryukov 11-Feb-13 4:39am    
Why do you think ClientID is used? ClientID is rendered as "id" in HTML, so the result will be identical; is it not?
—SA

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