Why can't I see the generated identifiers for the server side controls?

Now I'm a little confused. Let me explain:

I saw people talking about adding a button or some other control to a page in asp.net (3.5), and when the control displays it, the identifier of that control, for example. Button1 becomes Button1_somethings something that prevents them from using jQuery, and what they use is something like<%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 do not see how ASP.NET (asp.net 3.5) changes identifiers. Why am I seeing a different behavior?

Btw. It works when I press the button!

Thanks.

+3
4

ASP.NET , Naming Container. , ContentPlaceHolders (Repeater, GridView ..).

+9

YourControl.ClientID, , , .

+1

ASP.NET , , ContentPlaceHolder . , - ctl00_ContentPlaceHolderContent_Button1. .

0

INamingContainer ( asp: content, ).

MSDN:

, ID . , - , . , DataGrid, DataList, CheckBoxList, ChangePassword, LoginView, , SiteMapNodeItem RadioButtonList .

. ContentPlaceHolder. - .

0

Source: https://habr.com/ru/post/1706488/


All Articles