ToolBox Validation Control ValidationSummary

ValidationSummary Web Server Control

in ASP.NET environment,This article describes you how to work with ValidationSummary Web Control.The primary mechanism of the ValidationSummary is to list the bundle of Error message in the ValidationSummary Control.Use the ValidationSummary control to present the user with a list of validation errors that occurred when a form was posted to the server. The ValidationSummary also displays a back link for the user to return to the form and correct the data entry.

The ValidationSummary control allows you to summarize the error messages from all validation controls on a Web page in a single location. The summary can be displayed as a list, a bulleted list, or a single paragraph, based on the value of the DisplayMode property. The error message displayed in the ValidationSummary control for each validation control on the page is specified by the ErrorMessage property of each validation control

The following code snippets explains you the ValidationSummary

<form id="Form2" runat="server">
    <table cellpadding="10">
        <tr>
            <td>
                <table bgcolor="#eeeeee" cellpadding="10">
                    <tr>
                        <td colspan="3">
                            <b>Credit Card Information</b>
                        </td>
                    </tr>
                    <tr>
                        <td align="right">
                            Card Type:
                        </td>
                        <td>
                            <asp:RadioButtonList ID="rb1" RepeatLayout="Flow"
 runat="server">
                                <asp:ListItem>MasterCard</asp:ListItem>
                                <asp:ListItem>Visa</asp:ListItem>
                            </asp:RadioButtonList>
                        </td>
                        <td align="middle" rowspan="1">
                            <asp:RequiredFieldValidator ID="rfv1" 
ControlToValidate="rb1"
                                ErrorMessage="Card Type." Display="Static"
 InitialValue="" Width="100%" Text="*"
                                runat="server" />
                        </td>
                    </tr>
                    <tr>
                        <td align="right">
                           User Id:
                        </td>
                        <td>
                            <asp:TextBox ID="txt1" runat="server" />
                        </td>
                        <td>
             <asp:RequiredFieldValidator ID="RequiredFieldValidator2" 
ControlToValidate="txt1"
                                ErrorMessage="User Id. " Display="Static" 
Width="100%" Text="*" runat="server" />
                        </td>
                    </tr>
                    <tr>
                        <td>
                        </td>
                        <td>
                   <asp:Button ID="btn1" Text="Validate" runat="server" />
                        </td>
                        <td>
                        </td>
                    </tr>
                </table>
            </td>
            <td valign="top">
                <table cellpadding="20">
                    <tr>
                        <td>
                            <asp:ValidationSummary ID="valSum" 
DisplayMode="BulletList" EnableClientScript="true"
HeaderText="fill all the fields:" runat="server" />
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
    </table>
</form>

        
 
Related Links

Posted by: Admin
Posted on: 9/14/2009 at 5:23 PM
Tags: , ,
Categories: Asp.net
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (49) | Post RSSRSS comment feed

ToolBox Validation Control RequiredFieldValidator

RequiredFieldValidator Web Server Control

in ASP.NET environment,This article describes you how to work with RequiredFieldValidator Web Control.The RequiredFieldValidator can be used where without filling up an controls such as textbox.It restricts the user to specify the information in a desired textbox before leaving it.

Use this control to make an input control a required field. The input control fails validation if its value does not change from the InitialValue property upon losing focus. Multiple validators can be associated with the same input control. For example, a RequiredFieldValidator can be used to ensure input to a control, while at the same time a RangeValidator can be used to ensure that the input is within a specified data range.

To validate a required entry
  • Go to Design View,Includes a RequiredFieldValidator control to the page and set the following properties:
    • ControlToValidate -The ID of the control for which the user must provide a value.
    • ErrorMessage, Text, Display -Properties that specify the text and location of the error or errors that will appear if the user skips the control.
  • Add a test in your ASP.NET Web page code to check for validity

The following code snippets explains you the RequiredFieldValidator

<asp:Textbox id="txt1" runat="server"></asp:Textbox>
<asp:RequiredFieldValidator id="rfv1" runat="server"
  ControlToValidate="txt1"
  ErrorMessage="it is a required field."
  ForeColor="Red">
</asp:RequiredFieldValidator>
                  
 
Formating the RequiredFieldValidator

ASP.NET validation controls allows you to customizing the format—font, size, and so on—of error text, or you can substitute a marker for error text. For example, you can have the validation control display an asterisk (*) when an error occurs.

You can also include a detailed error message in the ErrorMessage property of the validation control and add a ValidationSummary control to the page. The detailed ErrorMessage property text will appear on the page in the location of the ValidationSummary control.

To format error messages, specify the following properties,
  • ForeColor - The color of the error message text.
  • BackColor -The color behind the text.
  • Font -The font face, size, weight, and so on.
  • BorderWidth, BorderColor, and BorderStyle -The size and color of a border around the error message.

The following example demonstrates how to use the RequiredFieldValidator control to make sure that the user enters a value into the text box.

in .aspx.cs page,

void ValidateBtn_Click(Object sender, EventArgs e) 
      {
 
         if (Page.IsValid) 
         {
            lblOutput.Text = "ok!";
         }
         else 
         {
            lblOutput.Text = "not ok!";
         }
      }        

in .aspx.cs page,

<table bgcolor="#eeeeee" cellpadding="10">
         <tr valign="top">
            <td colspan="3">
               <asp:Label ID="lblOutput" 
                    Text="Fill in the required field below"
                    runat="server"/>
               <br>
            </td>
         </tr>
 
         <tr>
            <td colspan="3">
               <b>Credit Card Information</b>
            </td>
         </tr>
     
         <tr>
            <td align="right">
               Card Number:
            </td>
            <td>
               <asp:TextBox id="TextBox1" 
                    runat="server"/>
            </td>
            <td>
               <asp:RequiredFieldValidator id="RequiredFieldValidator2"
                    ControlToValidate="TextBox1"
                    Display="Static"
                    ErrorMessage="*"
                    runat="server"/> 
            </td>
         </tr>
         <tr>
            <td></td>
            <td>
               <asp:Button id="Button1" 
                    Text="Validate" 
                    OnClick="ValidateBtn_Click" 
                    runat="server"/>
            </td>
            <td></td>
         </tr>
      </table>
     
 
Related Links

Posted by: Admin
Posted on: 9/14/2009 at 5:22 PM
Tags: , ,
Categories: Asp.net
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (46) | Post RSSRSS comment feed

ToolBox Validation Control RegularExpressionValidator

RegularExpressionValidator Web Server Control

in ASP.NET environment,This article describes you how to work with RegularExpressionValidator Web Control.It is an another Validation Contorl which can be performed an Operation as Checks that the entry matches a pattern defined by a regular expression.

This type of validation enables you to check for predictable Expressions, such as in e-mail addresses, telephone numbers, postal codes, and so on. The regular-expression validation implementation is different on the client than on the serve.

The following code snippets explains you the RegularExpressionValidator control

<asp:RegularExpressionValidator ID="Rev1" ControlToValidate="txt1"
 ValidationExpression="\d{7}"
    Display="Static" ErrorMessage="Zip code must be 7 numeric digits"
 EnableClientScript="False"
    runat="server" /<
 
Formating the RegularExpressionValidator

ASP.NET validation controls allows you to customizing the format—font, size, and so on—of error text, or you can substitute a marker for error text. For example, you can have the validation control display an asterisk (*) when an error occurs.

You can also include a detailed error message in the ErrorMessage property of the validation control and add a ValidationSummary control to the page. The detailed ErrorMessage property text will appear on the page in the location of the ValidationSummary control.

To format error messages, specify the following properties,
  • ForeColor - The color of the error message text.
  • BackColor -The color behind the text.
  • Font -The font face, size, weight, and so on.
  • BorderWidth, BorderColor, and BorderStyle -The size and color of a border around the error message.

The following example demonstrates how to use the RequiredFieldValidator control to make sure that the user enters a value into the text box.

in .aspx.cs page,

void ButtonClick(Object sender, EventArgs e)
      {
         if (Page.IsValid)
         {
            Label1.Text="valid page";
         }
         else
         {
            Label1.Text="not valid page!";
         }
      }
        

in .aspx page,

<form id="Form2" runat="server">
    <table bgcolor="#eeeeee" cellpadding="10">
        <tr valign="top">
            <td colspan="3">
                <asp:Label ID="lblOutput" Text="Enter a 7 digit zip code"
 runat="server" />
            </td>
        </tr>
        <tr>
            <td align="right">
                Zip Code:
            </td>
            <td>
                <asp:TextBox ID="TextBox1" runat="server" />
            </td>
            <td>
       <asp:RegularExpressionValidator ID="rev1" ControlToValidate="txt1"
         ValidationExpression="\d{7}" Display="Static" 
 ErrorMessage="Zip code must be 7 numeric digits"
                    EnableClientScript="False" runat="server" />
            </td>
        </tr>
        <tr>
            <td>
            </td>
            <td>
                <asp:Button ID="Button1" Text="Validate" 
OnClick="ValidateBtn_Click" runat="server" />
            </td>
            <td>
            </td>
        </tr>
    </table>
</form>

     
 
Related Links

Posted by: Admin
Posted on: 9/14/2009 at 5:21 PM
Tags: , ,
Categories: Asp.net
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (109) | Post RSSRSS comment feed

ToolBox Validation Control RangeValidator

RangeValidator Web Server Control

in ASP.NET environment,This article describes you how to work with RangeValidator Web Control.This control can be used to ensure the entered values within a desired range menas that Checks that a user's entry is between specified lower and upper boundaries. You can check ranges within pairs of numbers, alphabetic characters, and dates.

The RangeValidator control uses four key properties to perform its validation. The ControlToValidate property contains the input control to validate. The MinimumValue and MaximumValue properties specify the minimum and maximum values of the valid range. The BaseCompareValidator.Type property is used to specify the data type of the values to compare. The values to compare are converted to this data type before the validation operation is performed.

The following data types that can be compared.

  • String
  • Integer
  • Double
  • Date
  • Currency

The following code snippets explains you the RequiredFieldValidator

<asp:RangeValidator id="Range1"
ControlToValidate="txt1"
MinimumValue="10"
MaximumValue="100"
Type="Integer"
EnableClientScript="false"
Text="The value from 10 to 100!"
runat="server"/>
                  
 
Formating the RangeValidator

ASP.NET validation controls allows you to customizing the format—font, size, and so on—of error text, or you can substitute a marker for error text. For example, you can have the validation control display an asterisk (*) when an error occurs.

You can also include a detailed error message in the ErrorMessage property of the validation control and add a ValidationSummary control to the page. The detailed ErrorMessage property text will appear on the page in the location of the ValidationSummary control.

To format error messages, specify the following properties,
  • ForeColor - The color of the error message text.
  • BackColor -The color behind the text.
  • Font -The font face, size, weight, and so on.
  • BorderWidth, BorderColor, and BorderStyle -The size and color of a border around the error message.

The following example demonstrates how to use the RequiredFieldValidator control to make sure that the user enters a value into the text box.

in .aspx.cs page,

void ButtonClick(Object sender, EventArgs e)
      {
         if (Page.IsValid)
         {
            Label1.Text="value in range";
         }
         else
         {
            Label1.Text="value in not range!";
         }
      }
        

in .aspx page,

<form id="Form2" runat="server">
    <h3>
        RangeValidator Example</h3>
    Enter a number from 1 to 10:
    <br>
    <asp:TextBox ID="txt1" runat="server" />
    <br>
    <asp:RangeValidator ID="Range1" ControlToValidate="txt1"
 MinimumValue="10" MaximumValue="100"
        Type="Integer" EnableClientScript="false" Text="The value from
 10 to 100!"
        runat="server" />
    <br>
    <br>
    <asp:Label ID="Label1" runat="server" />
    <br>
    <br>
    <asp:Button ID="Button1" Text="Submit" OnClick="ButtonClick" 
runat="server" />
</form>
     
 
Related Links

Posted by: Admin
Posted on: 9/14/2009 at 5:20 PM
Tags: , ,
Categories: Asp.net
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (32) | Post RSSRSS comment feed

ToolBox Validation Control CustomValidator

CustomValidator Web Server Control

in ASP.NET environment,This article describes you how to work with CustomValidator Web Control.This control allows you to verify the entered value at run time.and also Checks the user's entry using validation logic that you write yourself. This type of validation enables you to check for values derived at run time.

The CustomValidator control is a separate control from the input control it validates, which allows you to control where the validation message is displayed.in ASP.NET Validation controls perform validation on the server everytime.

The following code snippets explains you the RegularExpressionValidator control

<asp:CustomValidator ID="CustomValidator1" ControlToValidate="txt1"
 Display="Static"
    ErrorMessage="not ok!" ForeColor="green" Font-Name="verdana"
 Font-Size="10pt"
    OnServerValidate="ServerValidation" runat="server" />
 
Formating the CustomValidator

ASP.NET validation controls allows you to customizing the format—font, size, and so on—of error text, or you can substitute a marker for error text. For example, you can have the validation control display an asterisk (*) when an error occurs.

You can also include a detailed error message in the ErrorMessage property of the validation control and add a ValidationSummary control to the page. The detailed ErrorMessage property text will appear on the page in the location of the ValidationSummary control.

To format error messages, specify the following properties,
  • ForeColor - The color of the error message text.
  • BackColor -The color behind the text.
  • Font -The font face, size, weight, and so on.
  • BorderWidth, BorderColor, and BorderStyle -The size and color of a border around the error message.

The following example demonstrates how to use the CustomValidator

in .aspx.cs page,

void ButtonClick(Object sender, EventArgs e)
      {
         if (Page.IsValid)
         {
            Label1.Text="valid page";
         }
         else
         {
            Label1.Text="not valid page!";
         }
      }
void meth1(object source, ServerValidateEventArgs args)
      {
         try 
         {
            int i = int.Parse(args.Value);
            args.IsValid = ((i%2) == 0);
         }

         catch(Exception ex)
         {

            args.IsValid = false;

         }
      }
        

in .aspx page,

<form id="Form2" runat="server">
    <h3>
        CustomValidator ServerValidate Example</h3>
    <asp:Label ID="Message" Text="specify no:" Font-Name="Verdana"
 Font-Size="10pt"
        runat="server" />
    <p>
        <asp:TextBox ID="txt1" runat="server" />
          
        <asp:CustomValidator ID="CustomValidator1" ControlToValidate="txt1"
 Display="Static"
            ErrorMessage="not ok!" ForeColor="green" Font-Name="verdana"
 Font-Size="10pt"
            OnServerValidate="ServerValidation" runat="server" />
    <p>
        <asp:Button ID="Button1" Text="Validate" OnClick="ValidateBtn_OnClick"
 runat="server" />
</form>
     
 
Related Links

Posted by: Admin
Posted on: 9/14/2009 at 5:20 PM
Tags: , ,
Categories: Asp.net
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (63) | Post RSSRSS comment feed