RequiredFieldValidator , ValidationSummary

Posted by Joggee | ASp.NET 2005 | Thursday 3 January 2008 1:05 pm

One of my readers asked me to write about validation summary of ASP.NET 2005.

A small example to help those who never used validate summary before.

I am using validationsummary control and RequiredFieldValidator to let you guys understand. 

Brief introduction:

Validation Summary:
The ValidationSummary control is used to display a summary of all validation errors  occurred in a Web page.

The error message displayed in this control is specified by the ErrorMessage  property of each validation control. If the ErrorMessage property of the validation  control is not set, no error message is displayed for that validation control.

For more detail click here.

RequiredFieldValidator:

The RequiredFieldValidator control is used to make an input control a required field.

For more detail click here

 Use below code,copy it and test at your webpage.

<table width=”100%” cellpadding=”1″ cellspacing=”6″>            <tr>                <td>                    <asp:ValidationSummary ID=”ValidationSummary1″ runat=”server” ShowSummary=”true” />                </td>            </tr>            <tr>                <td>                    <table>                        <tr>                            <td>                                <asp:TextBox ID=”TextBox1″ runat=”server”></asp:TextBox></td>                            <td>                                <asp:RequiredFieldValidator ID=”RequiredFieldValidator1″ runat=”server” ControlToValidate=”TextBox1″                                    ErrorMessage=”Missing field One” SetFocusOnError=”True” Display=”None”> </asp:RequiredFieldValidator></td>                        </tr>                        <tr>                            <td>                                <asp:TextBox ID=”TextBox2″ runat=”server”></asp:TextBox></td>                            <td>                                <asp:RequiredFieldValidator ID=”RequiredFieldValidator2″ runat=”server” ControlToValidate=”TextBox2″                                    Display=”none” ErrorMessage=”Missing field two” SetFocusOnError=”True”></asp:RequiredFieldValidator></td>                        </tr>                        <tr>                            <td align=”center” colspan=”2″>                                <asp:Button ID=”Button1″ runat=”server” Text=”Submit” /></td>                        </tr>                    </table>                </td>            </tr>

        </table>

For any further help, write me.

Rana

2 Comments »

  1. Comment by Naveed Mazhar — January 4, 2008 @ 8:15 am

    Thanks a lot. The problem is solved after reading your article.

  2. Comment by Sohaib Ahmad — January 4, 2008 @ 1:12 pm

    The artical on Validation Summary and RequiredFieldValidator is very informative.
    Also write something about Image and Text Verification on registration form.
    Advance Thanks.

RSS feed for comments on this post. TrackBack URI

Leave a comment