Solved

c#, asp.net- Group validation for a form, one error message for all fields

Posted on 2009-04-15
4
701 Views
Last Modified: 2012-05-06
Hi,
I have a form on my aspx page that has several fields , I want to make sure each field is filled in before submiting. I have the group validation on each text input box and the same group validation on the button, but I want an error message to show when the submit button is clicked and the validation group is not valid( not all fields have been filled in)
Is this possible?
Thanks
<div>

                                	<label for="eventName">Event Name: *</label> <asp:TextBox ID="eventName" runat="server"></asp:TextBox>

                                	<asp:RequiredFieldValidator ID="RequiredFieldValidator7" ControlToValidate="eventName" ValidationGroup="RegisterValidation" runat="server"  Display="Dynamic" />

                                </div>

       

                                <div>

                                	<label for="venueName">Venue Name: *</label> <asp:TextBox ID="venueName" runat="server"></asp:TextBox>

                                	<asp:RequiredFieldValidator ID="RequiredFieldValidator6" ControlToValidate="venueName" ValidationGroup="RegisterValidation" runat="server"  Display="Dynamic" />

                                </div>
 

<div>

                                	<label for="town">Town: *</label> <asp:TextBox ID="town" runat="server"></asp:TextBox>

                                	<asp:RequiredFieldValidator ID="RequiredFieldValidator69" ControlToValidate="town" ValidationGroup="RegisterValidation" runat="server"  Display="Dynamic" />

                                </div>

                                
 
 

 <asp:Button ID="SubmitButton" runat="server" OnClick="AddParkDetails" Text="Button" CssClass="submitButton" ValidationGroup="RegisterValidation"  />

Open in new window

0
Comment
Question by:CharlieDev
  • 2
  • 2
4 Comments
 
LVL 14

Expert Comment

by:GiftsonDJohn
ID: 24146374
Hi

Use ValidationSummary control and set the properties
ShowMessageBox = true
ShowSummary = false
0
 

Author Comment

by:CharlieDev
ID: 24146414
Thanks , do you have an example of how I use it?
0
 
LVL 14

Accepted Solution

by:
GiftsonDJohn earned 500 total points
ID: 24146663
I have included a validation summary control in your example.
 <div>

        <label for="eventName">

            Event Name: *</label>

        <asp:TextBox ID="eventName" runat="server"></asp:TextBox>

        <asp:RequiredFieldValidator ID="RequiredFieldValidator7" ControlToValidate="eventName"

            ValidationGroup="RegisterValidation" runat="server" Display="Dynamic" />

    </div>

    <div>

        <label for="venueName">

            Venue Name: *</label>

        <asp:TextBox ID="venueName" runat="server"></asp:TextBox>

        <asp:RequiredFieldValidator ID="RequiredFieldValidator6" ControlToValidate="venueName"

            ValidationGroup="RegisterValidation" runat="server" Display="Dynamic" />

    </div>

    <div>

        <label for="town">

            Town: *</label>

        <asp:TextBox ID="town" runat="server"></asp:TextBox>

        <asp:RequiredFieldValidator ID="RequiredFieldValidator69" ControlToValidate="town"

            ValidationGroup="RegisterValidation" runat="server" Display="Dynamic" />

    </div>

    <asp:ValidationSummary ID="ValidationSummary1" runat="server" ShowMessageBox="true" ShowSummary="false" ValidationGroup="RegisterValidation" />

    <asp:Button ID="SubmitButton" runat="server" OnClick="AddParkDetails" Text="Button"

        CssClass="submitButton" ValidationGroup="RegisterValidation" />

Open in new window

0
 

Author Closing Comment

by:CharlieDev
ID: 31570344
Thanks very much  :)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Error in query expression 3 37
About delegates in c sharp 3 38
Connection String 16 43
Close form "before" open 3 28
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now