Asp.net front-end js and back-end get the control in FormView. Take TextBox as an example, formviewtextbox

Source: Internet
Author: User

Asp.net front-end js and back-end get the control in FormView. Take TextBox as an example, formviewtextbox
I. Foreground js gets the control in FormView

Js to get the front-end control ID, such as TextBox (set its ID to TextBox1 here), we all know that it is a document. getElementById ("<% = TextBox1.ClientID %>"), but if the control is placed in FormView, this cannot be obtained, and an error is reported, prompting that TextBox1 cannot be found. In this case, to obtain the TextBox ID, use the following statement:

Document. getElementById ('<% = FormView1.FindControl ("TextBox1"). ClientID %>. (Note: Here FormView1 is the ID of FormView)

2. Obtain controls in FormView in the background

The background call is similar to the foreground call, as shown below:

TextBox TextBox1 = FormView1.FindControl ("TextBox1") as TextBox;

FindControl () is a server Control with the specified id parameter found in the current named container. It is of the Control type, and as TextBox converts the Control found to the desired type, in this example, TextBox is used.

You can also use the following method: TextBox TextBox1 = (TextBox) FormView1.FindControl ("TextBox1 ");

 

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.