ArticleDirectory
What is form?
<Form> tags are one of the most important tags in HTML and one of our most commonly used tags. However, I would like to say that in many basic. netProgramIn the mind of a clerk, he is the mother of a control. He may not be clear about his role. Form is a form used to post data to the server. In traditional web development (development without the concept of controls), the form tag is written as follows:<Form ID = "form1" Action = "" method = "Post">... </form>(You can see the HTML generated by Asp.net.Source code).
Id. What is the action? What is method?
Get and post
Action is the address to which the form is submitted (the page to which the request is sent), and method is the get or POST method )."Submit" is actually a page request., But some will send data, and some will not.
HTML generated by ASP. NETCodeYou will see that action is your own? What does this mean?
When the user clicks the submit button,Again, I requested my own page.And the submitted data is processed. The specific processing process will be included in the following chapter.
We know that the HTTP protocol has two types of requests: Get and post (put and delete, which are not discussed here ). As the name suggests, get is "get", post is "send" -- that is, submit data to the server. The server processes post data through the page specified by Action (request. Form ["inputname"] to obtain the specific control value ).
In this case, there is a new problem. Can the form method be set to get? What are their differences?
Method can be set to get. However, the get access URL is not used to send data to the server, but is only used to obtain the data.
Therefore, if we want to send the form data to the server, we can only put the data in the URL parameters. The server can obtain the control value through request. querystring ["inputname.
However, the URL length is limited and is in plain text, soThe get method cannot submit big data and private data.. However, post does not have this restriction, so it is suitable for submitting large amounts of data.
Submit
Submit means "Submit.
But why is there no submit control in ASP. NET?Only <asp: button/>. In fact, you can see that webform has "made" A submit button for us by checking the webpage source code, but we are not familiar with it.
The label of the submit button is <input type = "Submit"/>, but the tag generated by the ASP. NET button is <input type = "button">. Button cannot trigger form submission. only submit can trigger form submission.
Note that I have added a new word, form submission! Yes. What is form? Why is it submitted again? Isn't it a button?
In the browser, all HTML nodes and JS variables are prototype of window (refer to the fifth version of the Javascript authoritative guide ).
Form1 (Form ID) This form is a DOM instance. He has his own members, events, methods (please refer to the http://www.w3school.com.cn/htmldom/dom_obj_form.asp for details), one of which is submit ()!
Although ASP. NET does not use submit, he uses JavaScript to write a small method to call the submit method of form to implement form submission.
Therefore, when developing a webpage, we can also call the form submit by ourselves. Of course, we can do some processing before submitting (such as filling in the verification information ).
Code example:
< Html >
< Head >
< Script Type = "Text/JavaScript" >
Function Formsubmit ()
{
Document. getelementbyid ( " Myform " ). Submit ()
}
</ Script >
</ Head >
< Body >
< Form ID = "Myform" Action = "Js_form_action.asp" Method = "Get" >
Firstname: < Input Type = "Text" Name = "Firstname" Size = "20" > < BR />
Lastname: < Input Type = "Text" Name = "Lastname" Size = "20" > < BR />
< BR />
< Input Type = "Button" Onclick = "Formsubmit ()" Value = "Submit" >
</ Form >
</ Body >
</ Html >