How to make getElementById in an ASP.NET control

I have an element on my page.

<asp:Button ID="buttonToFind" runat="server" OnClick="SomeProcess" />

In javascript, I am trying to find this control using:

document.getElementById("buttonToFind");

However, he cannot find control. I understand that the asp: Button changes to an input element? This entry has a new identifier that contains the original identifier, but with a lot of extra characters, so I can not find the original identifier on the page?

Is it correct?

This is also given, how would I like to specify the correct identifier for the search?

+3
source share
4 answers

, yuo ClientId , Javascript:)

document.getElementById('<%= buttonToFind.ClientID %>'); 

0

ClientID . ASP.NET 4 ClientIDMode Static.

+3

Your understanding is correct.

This will work if JS is in ASPX / ASCX markup:

document.getElementById('<%= buttonToFind.ClientID %>');

If JS is external, you need to do extra work (for example, use a literal to store identifiers or register a script).

+1
source

You need to get the server management client ID:

document.getElementById("<%=buttonToFind.ClientID%>");
0
source

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


All Articles