0

下午所有,

我有一个网络表单,希望我的用户填写。在表单上,​​我希望在三个字段上设置验证。其中一个是普通文本框,另一个是与日历图标关联的文本框,我的最后一个字段是一个下拉列表,其中包含从枚举列表填充的数据。

我还不太担心我的下拉列表,但我对另外两个文本框感到有些沮丧。我在这两个上都使用了“必需的归档验证器”,并且只希望在用户单击提交按钮时启动验证。目前,如果您在这两个字段之间进行选项卡或单击,验证就会启动。

这是我的网络表格....

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

如果有人不能指出我正确的方向,那就太好了。提前谢谢了。

贝蒂

4

1 回答 1

0

您可以将 RequiredFieldValidator 的 EnableClientScript 属性设置为 false:

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

这样,只有在用户发布表单后才会进行验证。希望这可以帮助,

谢。

于 2012-06-25T15:10:03.053 回答