|
|
ASP.NET Tutorial 7: Intro to .NET Forms
by Matt on 2010/03/22 at 2:12 pm
Your web browser functions by sending requests to a web server, and then interpreting the web server’s response. Headers are the data that your browser sends to the server, or receives from the server as part of this “invisible” request-receive communication process.
There are two types of headers: Request and Response. Request Headers are those that your browser sends to a server, usually to tell the server that you want it to give you a specific webpage or file (ie: Request information). When you send form data to a server using the POST method, that data is sent along with the headers (using each form element’s “NAME” attribute). Alternatively, when you send a form using the GET method, the data is passed along in the query string (URL) instead. Response Headers are the headers that the server sends back to your browser, usually followed by whatever data your browser requested.
You can use Request["fieldname"] or Request.Form["fieldname"] to get POST data as easily as you can use Request.QueryString("fieldname") to fetch GET data. This is particularly handy if an ASPX page needs to process data sent to it from a different page.
When sending data to a webpage using the GET method, the form data is passed along as part of the URL. Data passed this way is referred to as a “querystring”. Data passed along as a querystring is encoded (because in order to be a valid URL certain characters need to be replaced) and sent as key-value pairs. The “key” is the name of the field, and “value” is whatever data was contained in that field. A URL with GET data in it looks something like this:
www.example.com/?key1=value1&key2=value2&key3=value3 The querystring starts with a question mark ( ? ) and each following key-value pair starts with an ampersand ( & ). Part of the encoding process replaces these characters with placeholders so that the URL remains valid and the querystring does not break. Encoding (and decoding, when you are working with data sent this way) is handled automatically by .NET. Prerequisites: A basic understanding of HTML form elements.
This article introduces the use of forms in an ASP.NET webpage. Before you begin, you should already have a basic understanding of HTML form elements. If you need a refresher, we will briefly discuss the use of classic form elements on an ASPX page, but the focus of this article will be on the use special ASP.NET form elements. That’s it for ASPX form basics. If you need to brush up on your classic HTML forms, I recommend checking out W3Schools.com. There’s really not a lot of difference between building forms in classic HTML and building them in .NET (other than some terminology) – but if you don’t already have a basic understanding of HTML forms, understanding them in .NET is even more difficult. The next article will deal more closely with what you do with form data once the user has submitted it.
• Posted under Tutorials and tagged with @Complexity: Beginner, ASP.NET, Forms, Visual Studio, Visual Web Developer
|
No Comments