How to get HTML controls from the background in ASP.

Source: Internet
Author: User

For example, the text box that defines HTML is as follows:

<input type= "text" onclick= "Fun ()" id= "Htmltxtdate"/>

To programmatically get the value of the text box in a background C # program, an easy way is to:

Add runat= "Server" to the HTML control, and then in the background C # code:this. Control Id.value. For example:

<input type= "text" onclick= "Fun ()" id= "htmltxtdate" runat= "Server" />

Then C # inside Label1.Text = Htmltxtdate.value;

But this method does not feel very good: because this input box is HTML, add the runat= "Server" is also the servers control, it is better to simply use vs provided TextBox control, or a little sibuxiang.

Of course, sometimes it is to use HTML text box to make other things easier, but also in the background to access the value of it, how to do?

This also has a workaround: do not runat= "server", in the background code can write: request.form["Txtname"]. ToString (); You can get the value of the input box. Note: Txtname is the Name property value.

For example, the above example:<input type= "text" onclick= "Fun ()" name= "htmltxtdate" />

It is then accessed in the background as follows: Label1.Text = request.form["htmltxtdate"]. ToString ();

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.