codetoad.com
  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! || Forums || 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
Sponsored by: FindMyHosting - Web Hosting Search
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: 17022 times Rating (1 vote): 
 5 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 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. 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...

</form>

 

It takes only one attribute (runat="server"), which tells 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 height in 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 whether the 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:

 

http://www.gotdotnet.com/quickstart/aspplus/samples/classbrowser/cs/classbrowser.aspx?namespace=System.Web.UI.WebControls

 

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.






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'
Posted by :  Archive Import (Richie) at 14:06 on Thursday, September 04, 2003
Testing this Form dudes


To post comments you need to become a member. If you are already a member, please log in .

 



RELATED ARTICLES
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.
Creating a Dynamic Reports using ASP and Excel
by Jeff Anderson
A simple way to generate Excel reports from a database using Excel.
Create an ASP SQL Stored Procedure
by Jeff Anderson
A beginners guide to setting up a stored procedure in SQL server and calling it from an ASP page.
ASP Shopping Cart
by CodeToad Plus!
Complete source code and demo database(Access, though SQL compatible) to an ASP database driven e-commerce shopping basket, taking the user through from product selection to checkout. Available to CodeToad Plus! Members
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.
Creating an SQL Trigger
by Jeff Anderson
A beginners guide to creating a Trigger in SQL Server
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.
ASP.NET Forum Source Code
by ITCN
Complete open source website Forum and Discussion Board programmed in Microsoft dot Net 1.1 Framework with Visual Basic.
The asp:listbox control
by David Sussman, et al
The next HTML server control that we'll look at, <asp:listbox>, is very much related to <asp:dropdownlist>.
Concatenate strings in sql
by Jeff Anderson
A brief introduction to concatenating strings in an sql query (using SQL server or access databases).








Recent Forum Threads
•  Re: User input. Command line application.
•  email in bulk
•  problem displaying
•  Re: dynamic crystal report generation
•  reading text files line by line
•  Re: crystal report in windows C#.NET
•  is null or not an object error
•  Need to control remote machine
•  Re: convert minutes into hours and minutes


Recent Articles
What is a pointer in C?
Multiple submit buttons with form validation
Understanding Hibernate ORM for Java/J2EE
HTTP screen-scraping and caching
a javascript calculator
A simple way to JTable
Java Native Interface (JNI)
Parsing Dynamic Layouts
MagicGrid
Caching With ASP.Net


© Copyright codetoad.com 2001-2006