Introduction to the role and use of the hidden Tibetan Domain hidden in html _ HTML/Xhtml _ webpage Creation

Source: Internet
Author: User
Hidden fields are invisible to users on the page. The purpose of inserting a hidden field in a form is to collect or send information to facilitate use by the form processing program, the following describes how to use this hidden domain in practice. If you are interested, do not miss it. Basic Syntax:



Purpose:

1. The hidden field is invisible to users on the page. The purpose of inserting a hidden field in a form is to collect or send information to facilitate the use of the form processing program. When a viewer clicks the send button to send a form, information about hidden fields is also sent to the server.

2. Sometimes we need to give the user a message so that the user can submit the form to determine the user identity, such as sessionkey. of course, these things can also be implemented using cookies, but it is much easier to use hidden domains. there will be no browsers that do not support it, and users will be troubled by disabling cookies.

3. Sometimes there are multiple submission buttons in a form. How can I make the program clearly know that the user submitted the form by that button? We can write a hidden field and add onclick = "document. form. command. value = "xx" ". After receiving the data, we first check the value of command to know which button the user has submitted.

4. Sometimes a webpage has multiple forms. We know that multiple forms cannot be submitted at the same time, but sometimes these forms do interact with each other, we can add hidden fields to form to associate them.

5 javascript does not support global variables, but sometimes we have to use global variables, so that we can first store the value in a hidden field and its value will not be lost.

6. For example, if you press a button to bring up four small windows, the other three are automatically closed when you click a small window. however, IE does not support mutual calls between small windows. Therefore, you only need to write a hidden field in the parent window. When the value of the hidden field in the small window is close, you can turn it off.

Example: Use hidden to add 1 by clicking the submit button

Auto-increment .htm

The Code is as follows:




Implemented using a general Handler

Value auto-increment. ashx

The Code is as follows:


Int n = 0;
Public void ProcessRequest (HttpContext context ){
Context. Response. ContentType = "text/html ";

String path = context. Request. MapPath ("auto-increment .htm ");
String html = System. IO. File. ReadAllText (path );
// Determine whether the page is loaded for the first time
String viewstate = context. Request. Form ["_ viewstate"];
If (! String. IsNullOrEmpty (viewstate ))
{
// Click the post button
// Obtain the value of the hidden field
String s = context. Request. Form ["_ p"];
If (int. TryParse (s, out n ))
{
N ++;
Html = html. Replace ("@ n", n. ToString ());
}
}
Else
{
// When the page is loaded for the first time, values are assigned to the hidden fields corresponding to p and p.
Html = html. Replace ("@ n", n. ToString ());
}
Context. Response. Write (html );
}

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.