ASP.NET
  Home arrow ASP.NET arrow Page 4 - Input Validation With ASP.NET, Part 1
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 
Mobile Linux 
App Generation ROI 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
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.NET

Input Validation With ASP.NET, Part 1
By: Harish Kamath (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 36
    2004-02-16

    Table of Contents:
  • Input Validation With ASP.NET, Part 1
  • Making Friends
  • First Glance
  • If Looks Could Kill
  • Pizza Power
  • A Comparative Study

  • 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
     
     
    ADVERTISEMENT


    Input Validation With ASP.NET, Part 1 - If Looks Could Kill


    (Page 4 of 6 )

    In the previous example, I allowed the client to carry out input validation first. However, at times, you may want to shift this responsibility directly to the server. ASP.NET allows you to do this, simply by adding an additional attribute to your RequiredFieldValidator definition.


    <%@ Page Language="C#" %>
    <html>
    <head>
    <title>What's in a name</title>
    <basefont face="Arial">
    </head>
    <body>
    <form runat="server" method="POST" >
     
    <asp:label id="lblFirstName" runat="server" text="Your name, please? " />
    <asp:textbox id="strFirstName" runat="server"/>
     
    <asp:RequiredFieldValidator id="strFirstNameRFV"
    ControlToValidate="strFirstName" ErrorMessage="Don'
    t you have a name?"
    runat="
    server" EnableClientScript="false" ForeColor="#FF0000"
    BackColor="#CCCCCC" BorderWidth="2" BorderColor="#000000" Display="dynamic"
    Style="font-family:verdana;padding: 3px;font-weight:bold;font-size:10px" />
     
    <asp:button id="Submit" Text="Submit" runat="server"/>
    </form>
    </body>
    </html>

    I'm sure you're wondering why the number of attributes for the RequiredFieldValidator control has suddenly increased. A close inspection will reveal that most of these are responsible for the formatting of the error message. However, the first and most important change is the "EnableClientScript" attribute, a simple flag that can be set to "true" or "false", depending on whether or not you wish to carry out client-side validation. Set this to "true" (the default value) and all validations will be carried out on the client; set it to "false" and the server will take over the responsibility for input validation

    Next, we have the "Display" attribute. This is an interesting attribute, useful if you want to ensure that the error messages generated by the Validator do not destroy the design and layout of your Web pages. If this value is set to "dynamic", the area where the error message appears is hidden till such time as the error message is to be displayed

    Finally, I have a list of attributes to control the display of the error message:

    1. The ForeColor attribute controls the color used to display the error message.

    2. The BackColor attribute controls the background color for the area displaying the error message.

    3. The BorderWidth attribute controls the width of the border for the area displaying the message.

    4. The BorderColor attribute controls the color of the border around the message.

    5. The Style attribute allows you to specify CSS properties for the text of the error message.

    More ASP.NET Articles
    More By Harish Kamath (c) Melonfire


     

    ASP.NET ARTICLES

    - Developing a Mini ASP.NET AJAX Server Centri...
    - Disadvantages of the ASP.NET MVC Framework
    - Advantages of the ASP.NET MVC Approach
    - ASP.NET Web Forms Weaknesses
    - ASP.NET Web Forms Meets ASP.NET MVC
    - Source Code for Saving and Retrieving Data w...
    - Using GridView to Save and Retrieve Data wit...
    - Handling Dynamic Images in ASP.NET 3.5 AJAX ...
    - Retrieving Data with AJAX and the GridView C...
    - Playing with Images in ASP.NET 3.5 AJAX Appl...
    - Saving and Retrieving Data with AJAX
    - Enhancing PHP Via the ASP.NET AJAX Framework...
    - Enhancing PHP Programming with the ASP.NET A...
    - Classes and ASP.NET AJAX
    - Using ASP.NET AJAX

     
    Best Practices for Windows Vista Migration Presentation
    Dell and Microsoft recently held a series of face-to-face seminars entitled, &qu....

     
    Creating a Culture for Code Reuse
    If you oversee development teams you know that like it or not proprietary and ex....

     
    Keys to Web Application Acceleration: Advances in Delivery Systems
    Accelerate Web apps by up to 5x. Ensure significantly faster access to the Web a....

     
    Optimizing Application Monitoring
    Tired of finding out from your customers that you're offline? This white paper e....

     
    Solaris to Solaris Migration -- Migrating applications from Sun SPARC to Dell PowerEdge R900
    This comprehensive Migration Guide reviews the approach that Principled Technolo....

     




    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
    Stay green...Green IT