javascript operates on the ASP.NET server control

  • 2021-06-28 12:18:39
  • OfStack

When js is used in ASP.NET, js often fails to get DOM elements because of the incorrect method of getting them. Now we introduce method 1 to solve how to use js to get ASP.NET control to generate id tags corresponding to html tags on the browser side.

1. Get the id of the browser-side label generated by the server-side control, that is, the client-side html label id corresponding to the server control

The corresponding id value in the browser, client html tag, can be obtained by using the ClientID property of the server-side control as follows


<%= newsId.ClientID %>

2. Obtain corresponding dom elements from dom

It can be obtained from js, document or jquery. Here is an example of jquery


var newsId = $("#<%= newsId.ClientID %>");
var newsId = $("#<%= newsId.ClientID %>");

3. Operations on the dom element

Now that you have the elements you want to operate on, you can proceed with the corresponding operations. After that, it's up to you to start "doing whatever you want"~~


Related articles: