0

Afternoon All,

I have a web form that i wish my user to fill out. On the form i have three fields that i wish to set validation on. One of these is a normal textbox, the other a textbox associated with a calendar icon and my last field is a drop down list that has data held in it populated from an Enum list.

Im not too worried about my dropdown list yet, but i am getting slightly frustrated with my other two textboxes. I have used a 'Required Filed Validator' on both of these and only want the validation to kick in when the users clicks the submit button. At the moment if you tab or click between these two fields the validation kicks in.

Here is my web form....

          <table id="table-3">
          <tr>
                <td style="width: 385px"> 
                    <asp:Label ID="lblOrganiser" runat="server" Text="Meeting Organiser:">
                    </asp:Label></td>
                <td class="style4" style="width: 23px">                 
                   <asp:TextBox ID="txtOrganiser" runat="server" >
                    </asp:TextBox>      
                </td>
               <td>
                    <asp:RequiredFieldValidator ID="RequiredFieldVal0"
                     ControlToValidate="txtOrganiser" 
                     ErrorMessage="Meeting Organiser"
                     Text="*" 
                     runat="server"/>
               </td>
              <td>
                 <asp:Label ID="lblDate" runat="server" Width="40px" Text="Date:">
                 </asp:Label>
              </td>   
              <td class="style5">
                  <asp:TextBox ID="txtAgendaDate" runat="server" ForeColor="Black" >
                  </asp:TextBox>
                  <asp:ImageButton runat="Server" ID="ImageButton1" ImageUrl="~/images/contact_date_SM3.png" 
                AlternateText="Click here to display calendar" ImageAlign="AbsMiddle"  /> 
                  <asp:calendarextender ID="CalendarExtender3" runat="server" 
                    TargetControlID="txtAgendaDate" PopupButtonID="ImageButton1" Format="dd/MM/yyyy"></asp:calendarextender>
              </td>
              <td>
                 <asp:RequiredFieldValidator ID="RequiredFieldVal1"
                 ControlToValidate="txtAgendaDate" 
                 ErrorMessage="Date"
                 Text="*" 
                 runat="server"/>
              </td>
            </tr>

             <tr>
                <td style="width: 385px"><asp:Label ID="lblAgendaTypeDescription" runat="server" Text="Type Of Meeting:"></asp:Label></td>
                <td class="style4" style="width: 23px">
                    <asp:TextBox ID="txtAgendaTypeDescription" runat="server" Text="Monthly" BackColor="#F4F4F4" ReadOnly="True"></asp:TextBox>
                 </td>
                   <td></td>
           <td class="style7" style="width: 24px"><asp:Label ID="lblTime" runat="server" Text="Time"></asp:Label></td>
                <td><asp:TextBox ID="txtTime" runat="server" 
                        Text="4pm" style="margin-top: 2px"></asp:TextBox></td>
                 <td></td>
            </tr>
            <tr>
                <td style="width: 385px">
                    <asp:Label ID="lblVenue" runat="server" Text="Venue"></asp:Label>
                </td>
                <td class="style4"  colspan="6"><asp:TextBox ID="txtVenue" runat="server" 
                        Text="Room 1"  Width="550px" TextMode="SingleLine" ></asp:TextBox></td>
            </tr>
            <tr>
                <td style="width: 385px"><asp:Label ID="lblRead" runat="server" Text="Please Read:"></asp:Label></td>
                <td class="style4" colspan="6">
                    <asp:TextBox ID="txtRead" runat="server" 
                        Width="550px" TextMode="SingleLine" Font-Names="Verdana"  ></asp:TextBox></td>         
            </tr>
             <tr>
                <td style="width: 385px"><asp:Label ID="lblBring" runat="server" Text="Please Bring:"></asp:Label></td>
                <td class="style4" colspan="6">
                    <asp:TextBox ID="txtBring" runat="server" 
                        Width="550px" TextMode="SingleLine" Font-Names="Verdana"  ></asp:TextBox></td>         
            </tr>

            <tr>
                <td style="width: 385px"><asp:Label ID="lblAgendaStatus" runat="server" Text = "Agenda Status" ></asp:Label></td>
                <td class="style4" style="width: 23px">
                    <asp:DropDownList ID="AgendaStatus" 
                        runat="server" Height="24px" Width="125px"> </asp:DropDownList>        
                </td>    
                <td> <asp:RequiredFieldValidator ID="RequiredFieldVal2"
                 ControlToValidate="AgendaStatus" 
                 ErrorMessage="Agenda Status"
                 Text="*" 
                 runat="server"/>
                </td>                  
          </tr>
       </table>

        <br />
           <asp:ValidationSummary ID="ValidationSummary2"
            HeaderText="You must enter a value in the following fields:"
            DisplayMode="BulletList"
            EnableClientScript="true"
            runat="server"/>
            <br />

    <div style="text-align: right;">
                  <asp:ImageButton runat="Server" ID="btnAddMonthlyTemplate" ImageUrl="~/images/Addbutton.png" 
                AlternateText="Add Weekly Template"  /> 
          </div>

If anyone cant point me in the right direction that would be great. Many thanks in advance.

Betty

Betty B
  • 185
  • 1
  • 4
  • 20
  • See this question http://stackoverflow.com/questions/2855015/how-to-make-requiredfieldvalidator-error-message-display-after-click-submit-butt – Kevin Main Jun 25 '12 at 14:57
  • You want this property: ["EnableClientScript"](http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.basevalidator.enableclientscript.aspx), to be set to "false" in your `RequiredFieldValidator` markup. – Josh Darnell Jun 25 '12 at 15:00
  • Hmmm. How come you're not using [your usual account](http://stackoverflow.com/users/1016307/betty)? Just curious =) – Josh Darnell Jun 25 '12 at 16:09

1 Answers1

0

You can set the EnableClientScript property of the RequiredFieldValidator to false:

  <asp:RequiredFieldValidator ID="RequiredFieldVal1"
                 ControlToValidate="txtAgendaDate" 
                 ErrorMessage="Date"
                 Text="*" 
                 EnableClientScript="false"
                 runat="server"/>

that way the validation will accur only after the user posts the form. Hope this helps,

Shai.

Shai Aharoni
  • 1,955
  • 13
  • 25
  • It seems that the validation also kicks in for both textboxs when a user clicks the calendar icon as well. Is there any way to resolve this issue. Im using the calendar icon as part of Ajax, this enables the user to select a date through the Ajax calendar via the textbox? – Betty B Jun 25 '12 at 15:20
  • @Betty B - If your calendar icon is an ImageButton, you can set it's CausesValidation property to false. – MTAdmin Jun 25 '12 at 16:10
  • @MTAdmin - Many thanks this worked a treat. I have also set CausesValidation to false for my cancel button (Imagebutton) as this also had the same issue. Many Thanks. – Betty B Jun 28 '12 at 10:25