JS or jQuery method for obtaining the ASP. NET Server Control ID, jqueryasp.net

Source: Internet
Author: User

JS or jQuery method for obtaining the ASP. NET Server Control ID, jqueryasp.net

In ASP. when js is used in. NET, JavaScript often cannot obtain DOM elements because of incorrect methods. Now we will introduce a method to solve the problem of getting ASP using js.. NET controls generate the id corresponding to the html tag on the browser side

1. Obtain the id of the tag generated by the server control on the browser, that is, the client html Tag id of the server control.

The ClientID attribute of the server control can be used to obtain the corresponding id value in the browser, that is, the html tag of the client. The method is as follows:

The Code is as follows:
Copy codeThe Code is as follows:
<% = NewsId. ClientID %>

2. Get the corresponding dom Element Through dom

It can be obtained through js or document or jquery. Here we use jquery as an example.

The Code is as follows:
Copy codeThe Code is as follows:
Var newsId =$ ("# <% = newsId. ClientID %> ");

3. Operate dom elements

Now that you have obtained the elements to be operated, you can perform the corresponding operations. Then you can start to "do whatever you want ~~~

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.