ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || RAM 
Search Site:

Home » ASP » Article

ASP.NET : How the Form Tag Works in ASP.NET

Article by: David Sussman, et al (7/8/2002)
Bookmark us now! Add to Favourites
Email a friend!Tell a friend
Summary: ASP.NET has a set of form controls that can be used just like their HTML form control equivalents, the main difference being that they are actually constructed dynamically on the server and then sent out.
Viewed: 61224 times Rating (6 votes): 
 3.8 out of 5
 Rate this Article  Read Comments  Post Comments

Previous Page  Page 1 Page 2 Page 3  Page 5 Page 6 Page 7 Page 8 Page 9 Page 10 Page 11 Page 12 Page 13 Next Page  

How the <form> Tag Works in ASP.NET

ASP.NET has a set of form controlsthat can be used just like their HTML form control equivalents, the main difference being that they are actually constructed dynamically on the server and then sent out. There's another difference we'll need to look at first though.

As we explained earlier when using HTML form controls, we use a modified version of the <form> tag in ASP.NET. The ASP.NET version of the <form> tag looks like this:


<form runat="server">

... ASP.NET form...



It takes only one attribute (runat="server"), whichtells the web server that it should process the form itself, rather than just sending it out to the browser (which won't be able to interpret this ASP.NET-specific attribute). Even though we haven't specified the contents of the method and get attributes, ASP.NET is able to handle this itself and provide its own values. In fact all ASP.NET forms are sent by the POST method. If they are not sent by the POST method if you try to override it you will not be able to use the information in the form). We have a new version of the <form> tag, but how does that compare with the HTML version?


The <form> tag enables us to process form controls on the server. ASP.NET introduces its own customized versions of these controls. The ASP.NET server controls were introduced to solve many of the problems associated with the HTML form controls. For instance, if you go forward from a form on almost any web site, and then jump back again to make a correction, you will find that all of the information has disappeared. This is because HTTP is stateless, as we mentioned earlier: it has no concept of who is connecting to it, or when it just answers requests for a connection. However, ASP.NET now takes over some of these responsibilities of looking after and persisting this data.

ASP.NET Server Controls

In this next section, we're going to be demonstrating how each of the ASP.NET server controls work, and comparing the way they are used to the way their equivalent HTML form control passed information. We'll also demonstrate how we can start achieving our ambition of separating the presentational code (HTML) from the code that provides the content (ASP.NET).

The <asp:label> Control

We'll start with a small, but very useful little control, the <asp:label> control. This control provides an effective way of displaying text on your web page in ASP.NET. It mimics the HTML <span> tag, a tag that has no effect on the text it contains, but can be used to logically group text together into sections, paragraphs, pages, or sentences. This control is actually vital to us if we want to separate our HTML from our ASP.NET code.

The <asp:label> Control Attributes

The <asp:label> control is just like any normal HTML form control in that it has a collection of attributes you can set. We won't list them all, but ones you might wish to use are:


        BackColor sets the background color of the label

        ForeColor sets the foreground color of the label

        Height sets the heightin pixels of the label

        id sets a unique identifier for that particular instance of the label


        Text sets the text that you want the label to display

        Visible determines whetherthe label control is currently visible on the page: this must be either true or false

        Width sets the width of the label control


If you want a full detailed list of the attributes that the <asp:label> control supports (or indeed any HTML server control), then you can use a handy tool known as the class browser, which you can run from the following URL:


On the right-hand side of the page, you can find a list of all the controls, from label and dropdownlist, to checkbox and the likes. Clicking on the link for a particular control will a reveal a list of allowable attributes under the name Properties. We won't be supplying a list of attributes for the other controls, as, generally, they each support the same attributes, and this information is easily obtainable from the URL given above.


One other attribute not mentioned on the lists for any of the controls, but supported by all of them is the attribute runat, which is always set to server. This is to explicitly indicate that this particular control should be run on the server, not the browser.

Previous Page  Page 1 Page 2 Page 3  Page 5 Page 6 Page 7 Page 8 Page 9 Page 10 Page 11 Page 12 Page 13 Next Page  

Click here to Buy!

Buy Beginning ASP.NET with C# here

© Copyright 2002 Wrox Press This chapter is written by David Sussman, et al and taken from "Beginning ASP.NET with C#" published by Wrox Press Limited in June 2002; ISBN 1861007345; copyright Wrox Press Limited 2002; all rights reserved.

No part of these chapters may be reproduced, stored in a retrieval system or transmitted in any form or by any means -- electronic, electrostatic, mechanical, photocopying, recording or otherwise -- without the prior written permission of the publisher, except in the case of brief quotations embodied in critical articles or reviews.

Useful Links

CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums
Rate this article:     Poor Excellent
View highlighted Comments
User Comments on 'ASP.NET : How the Form Tag Works in ASP.NET'
ASP FilesystemObject
by Jeff Anderson
An introduction to the Filesystemobject
ASP GetTempName
by Jeff Anderson
Use the GetTempName method to create a randomly generated temporary file on the server.
ASP Format Date and Time Script
by Jeff Anderson
An ASP script showing the variety of date and time formats possible using the FormatDateTime Function.
ASP OpenTextFile
by Jeff Anderson
An introduction to the OpenTextFile Method of the FileSystemObject
Email validation using Regular Expression
by Jeff Anderson
Using regular expression syntax is an exellent way to thoroughly validate an email. It's possible in ASP.
Add or Subtract Hours in SQL or ASP using DateAdd
by Jeff Anderson
A beginners guide to using the SQL DATEADD function to add or subtract hours. Particularly useful when setting the time displayed on the ASP page to a different time zone (eg when the server is in the US, and the site is for a UK audience).
The asp:radiobutton and asp:radiobuttonlist control
by David Sussman, et al
In HTML, radio buttons are used when we need to make multiple sets of choices available, but we want the user to select only one of them.
The asp:checkbox and asp:checkboxlist control
by David Sussman, et al
Checkboxes are similar to radio buttons, and in HTML, they were used to allow multiple choices from a group of buttons.
Concatenate strings in sql
by Jeff Anderson
A brief introduction to concatenating strings in an sql query (using SQL server or access databases).
ASP FileExists
by Jeff Anderson
An introduction to the FileExistsMethod of the FileSystemObject

Recent Forum Threads
• Run a program both on windows and linux
• VERO.SurfCAM.v2014
• Schlumberger.Petrel.V2013.2
• Petrel.V2013.2
• Altair.HyperWorks.v12
• VoluMill.v6.1
• VoluMill.NEXION.6
• VERO.SurfCAM.v2014
• Schlumberger.Petrel.V2013.2

Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text

© Copyright 2001-2015