I’m little confused here now. Let me explain:
I’ve seen people talking about adding a button or some other control to the page in asp.net (3.5) and when the control renders it changes the Id of that control, eg. Button1 becomes Button1_somethingsomething which prevents them from using jQuery and what they end up using is something such as <%controlId.ClientId %>
So I did a little test
1. I added a button on the page: <form id='form1' runat='server'> <div> <asp:Button ID='Button1' runat='server' Text='Button' /> <div> 2. Then I added a JavaScript and jQuery: <script type='text/javascript'> $(document).ready(function() { $('#Button1').click(function() { alert('Hello world!'); }); }); </script> 3. The generated html is this: <div> <input type='submit' name='Button1' value='Button' id='Button1' /> <div>
Now, I don’t see ASP.NET (asp.net 3.5) changing the ids. Why do I see different behavior?
Btw. This does work when I hit the button!
Thanks.
ASP.NET only changes the IDs when the control is inside of a Naming Container. This could include certain user controls, ContentPlaceHolders from a master page, and repeating controls (Repeater, GridView, etc.)