Reputation: 43833
I have a asp control button that when I look at it in IE 9 developers tool I see it's id is
ctl00_m_g_0e632166_55b3_4470_971c_bd562d4904c8_ctl00_Button2
.
Is there a way I can access this id in the c# code?
Something like Button2.getID
?
Curently I am inserting javascript code that will need to find this control to do various things and the method I am using isn't good, it's basically checking if the suffix of all input id's is Button2
. I want to find a better way...
Thanks
Upvotes: 0
Views: 783
Reputation: 31077
If your control is not in a repater or grid, and it is unique to the page, you can set ClientIDMode="Static"
and it will be whatever ID you give it. Otherwise, you will have to use ClientID
as others have pointed out.
Upvotes: 2
Reputation: 136074
Button2.ClientID
is what you're looking for i think.
docs: http://msdn.microsoft.com/en-us/library/system.web.ui.control.clientid.aspx
You can also control how this is set by setting the ClientIDMode
Upvotes: 4