ASP Code
  Home arrow ASP Code arrow ASP Forms
Iron Speed
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Dedicated Servers 
Download TestComplete 
Windows Web Hosting
 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
ASP CODE

ASP Forms
By: James Payne
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 28
    2007-11-21

    Table of Contents:
  • ASP Forms
  • Cookies
  • A Baker's Dozen
  • Sessions
  • How to Store Sessions and Retrieve Them

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    Iron Speed
     
    ADVERTISEMENT

    Free Web 2.0 Code Generator! Generate data entry and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!

    ASP Forms
    (Page 1 of 5 )

    In our last tutorial we learned some of the basics of ASP, like syntax, printing data to the screen, how to create and manipulate variables, and even how to make arrays. I even slipped a for loop in on you to further boggle your puny brain. In this article, I detail the use of forms in ASP and how to retrieve user input.

    Forms

    If you didn't cheat and answered the questions in my first tutorial, then you should have a grasp of how to create forms in HTML. Here, I am going to teach you to retrieve the data the user enters into those forms. The first method we will discuss is the request.querystring.

    Request.QueryString

    The Request.QueryString command is used to retrieve values in forms with the Get Method (method="get"). That's similar to the method my girlfriend uses every time I get near near her, except that method is the Git! Method and involves a lot of door slamming.

    Data received from a form that utilizes the Get Method is visible to the public, as it is contained in the URL, and can only store limited information. Here is an example of how to use the Request.QueryString command:


    <html>
    <body>
    <form action="sample.asp" method="get">
    Please Enter Your Name: <input type="text" name="name"/>
    <input type="submit" value="Submit" />
    </form>
    <%
    dim name
    name=Request.QueryString("name")
    If name<>"" Then
    Response.Write("Hello " & name & "!<br />")
    Response.Write("You are my lord and savior!")
    End If
    %>

    </body>
    </html>

    The above code asks the user for their name and stores the value when the user clicks the Submit button. It then takes that value and says if the value is not equal to (<>)""(or basically so long as the value is not null), then write "Hello" to the screen and append the text in the variable "name," followed by more text: "You are my lord and savior". If the user does not enter any text into the text field, nothing will happen.

    Here is another example. First, let's create our HTML form:


    <form method="Get" action="sample.asp"

    Enter Your Name: <input type ="text" name ="name"/>

    Enter Your Occupation: <input type ="text" name ="occupation"/>

    <input type="Submit" value="Click to Submit"/>

    </form>

    Next, we will create our sample.asp page to process the information:

     

    <%

    Dim name, occupation

    name="Request.QueryString("name")

    occupation=Request.QueryString("occupation")

    response.write("Your name is: " & name & "<br />")

    response.write("Your current occupation is " & occupation & "<br />")

    %>

    If the user entered their name as Freddy Krueger and their Occupation as Crazy-assed Murderer, the following would be output to the screen:

      Your name is: Freddy Krueger

      Your current occupation is Crazy-assed Murderer

    Request.Form

    To collect data from forms that used the Post method (method=post), we use the Request.Form command. Unlike the Request.QueryString, the Request.Form command is invisible to the user (and thus will not appear in the URL), and there are no limits to the amount of data you can return.

    To begin, let's create our HTML page with the form on it:


    <form method="Post" action="anothersample.asp">

    Enter Your Name: <input type="text" name="name"/>

    Enter Your Occupation: <input type="text" name="occupation"/>

    <input type="submit" value="Click to Submit"/>

    </form>

    Next we create our ASP page (anothersample.asp) to retrieve the data:

     

    <%

    Dim name, occupation

    name=Request.Form("name")

    occupation=Request.Form("occupation")

    response.write("Your name is: " & name & "<br />")

    response.write("Your present occupation is: " & occupation & "<br />")

    %>

    This will result in the following printing out to your browser (if the user had supplied the name Jason Voorhees and the occupation Camp Counselor):

      Your name is: Jason Voorhees

      Your present occupation is: Camp Counselor

    More ASP Code Articles
    More By James Payne


       · how to data update,search,save in database through forms button
     

    ASP CODE ARTICLES

    - ASP Forms
    - ASP: The Beginning
    - Getting Remote Files With ASP Continued
    - Inbox and Outbox Manipulation in ASP
    - Relational DropDownList Using VB.NET
    - Ad Tracking URL Hits
    - Use ViewState to display one record per page...
    - Send Email using ASP.NET formatted in HTML
    - ASP File Explorer
    - ASP/XML Interview questions by Srivatsan Sri...
    - Various methods of setting Date values to a ...
    - Conditional DataGrid Item and using checkbox...
    - Fill .NET Listbox with SQL DataReader
    - Filling Dropdown box using Code-Behinds in C#
    - FLAMES code sample written in .NET What is F...

     
    Accelerating Trading Partner Performance
     
    Competing on Analytics
     
    Cost Effective Scaling with Virtualization and Coyote Point Systems
     
    Five Checkpoints to Implementing IP Telephony
     
    Hosted Email Security: Staying Ahead of New Threats
     




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway