在VB.Net中添加验证器后,无法加载.aspx页

时间:2019-05-22 16:17:38

标签: vb.net requiredfieldvalidator rangevalidator

我有一个aspx页面,其中包含一些FormViews和一个我想为其添加验证的可更新GridView。顺便说一句,我尝试验证的字段也使用了AJAX控制工具包中的CalendarExtender。我正在尝试为此使用RequiredFieldValidator和RangeValidator。问题是在添加验证器时,我没有在Visual Studio 2015中看到任何错误。但是,当我运行调试模式并单击按钮以打开包含验证的FormView时,出现500错误,但没有任何有用的信息来查找/解决我的问题。

我首先尝试一次添加两个验证器,但是遇到问题后,我只是试图使RequiredFiledValidator工作。但是我仍然需要知道如何使RangeValidator正常工作。对于RangeValidator,我要验证开始日期不少于今天并且结束日期大于开始日期。我尝试使用在这些页面上找到的所有示例:

[1] https://www.c-sharpcorner.com/UploadFile/17e8f6/requiredfieldvalidator-control-in-Asp-Net/

[2] https://asp.net-tutorials.com/validation/required-field-validator/

[3] http://www.java2s.com/Tutorial/ASP.NET/0160__Validation/UseaspRangeValidatortocheckthevaluerangeinanasptextbox.htm

[4] http://www.informit.com/articles/article.aspx?p=101137&seqNum=5

[5] https://docs.microsoft.com/en-us/dotnet/api/system.web.ui.webcontrols.rangevalidator.minimumvalue?view=netframework-4.8

[6] https://www.tutorialspoint.com/asp.net/asp.net_validators.htm

这是我尝试验证的FormView之一。在RangeValidator中,我只是对Max和Min值进行了硬编码,但最终我希望Min值与开始日期文本框中加上天的值相同:

      <asp:FormView ID="fvNotification" runat="server" Visible="False" DefaultMode="Insert" GridLines="Both" DataSourceID="SqlUserDetails">
           <InsertItemTemplate>
                 <asp:Table ID="Table1" runat="server">
                   <asp:TableHeaderRow>
                       <asp:TableHeaderCell>Notification</asp:TableHeaderCell>
                       <asp:TableHeaderCell>Filter 1</asp:TableHeaderCell>
                       <asp:TableHeaderCell>Filter 2</asp:TableHeaderCell>
                       <asp:TableHeaderCell>Begin Date</asp:TableHeaderCell>
                       <asp:TableHeaderCell>End Date</asp:TableHeaderCell>
                   </asp:TableHeaderRow>
                   <asp:TableRow>
                       <asp:TableCell>
                           <asp:DropDownList ID="ddNotification" runat="server" DataSourceID="SqlNotifications" DataTextField="Name" DataValueField="Name" ></asp:DropDownList></asp:TableCell>
                       <asp:TableCell>
                           <asp:DropDownList ID="ddFilterInsrt" runat="server" DataSourceID="SqlFilters1" DataTextField="Filter" DataValueField="Filter" ></asp:DropDownList></asp:TableCell>
                       <asp:TableCell>
                           <asp:DropDownList ID="ddFilterInsrt2 runat="server" >
                                <asp:ListItem>*</asp:ListItem>
                                <asp:ListItem>A</asp:ListItem>
                                <asp:ListItem>B</asp:ListItem>
                                <asp:ListItem>C</asp:ListItem>
                                <asp:ListItem>D</asp:ListItem>
                           </asp:DropDownList>
                       </asp:TableCell>
                     <asp:TableCell>
                         <asp:TextBox ID="TextBoxDateBgnInsrt" runat="server" autocomplete="Disabled" ></asp:TextBox>
                         <ajaxToolkit:CalendarExtender runat="server" BehaviorID="TextBoxDateBgnInsrt_CalendarExtender" TargetControlID="TextBoxDateBgnInsrt" ID="TextBoxDateBgnInsrt_CalendarExtender"></ajaxToolkit:CalendarExtender>
                       </asp:TableCell>
                       <asp:TableCell>
                           <asp:TextBox ID="TextBoxDateEndInsrt" runat="server" autocomplete="Disabled" ></asp:TextBox>
                           <ajaxToolkit:CalendarExtender runat="server" BehaviorID="TextBoxDateEndInsrt_CalendarExtender" TargetControlID="TextBoxDateEndInsrt" ID="TextBoxDateEndInsrt_CalendarExtender"></ajaxToolkit:CalendarExtender>
                           <asp:RangeValidator  runat="server" id="rngDate" controltovalidate="TextBoxDateEndInsrt" type="Date" MaximumValue='09/20/2011' MinimumValue="09/01/2011" errormessage="Please enter a valid date within 2006!" display="Dynamic"/>
                       </asp:TableCell>

                 </asp:TableRow>
               </asp:Table>
               <asp:Button ID="InsertButton" runat="server" CommandName="Insert" Text="Insert" CausesValidation="True" />
             &nbsp;<asp:Button ID="InsertCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" OnClick="InsertCancelButton_Click1" />
               &nbsp;<asp:Button ID="InsertClearEndDateButton" runat="server" Text="Clear End Date" OnClick="InsertClearEndDateButton_Click"/>

            </InsertItemTemplate>

        </asp:FormView>

我希望在单击使FormView可见的按钮后,FormView将可见并进行验证,但是却出现500错误。

0 个答案:

没有答案