vb.net - 在 VB.Net 中添加验证器后,.aspx 页面不加载
问题描述
我有一个带有几个 FormView 和一个可更新 GridView 的 aspx 页面,我想为其添加验证。顺便说一句,我要验证的字段也使用 AJAX 控件工具包中的 CalendarExtender。我正在尝试为此使用 RequiredFieldValidator 和 RangeValidator。问题是我在添加验证器时在 VisualStudio 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/
[4] http://www.informit.com/articles/article.aspx?p=101137&seqNum=5
[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" />
<asp:Button ID="InsertCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" OnClick="InsertCancelButton_Click1" />
<asp:Button ID="InsertClearEndDateButton" runat="server" Text="Clear End Date" OnClick="InsertClearEndDateButton_Click"/>
</InsertItemTemplate>
</asp:FormView>
我希望 FormView 在单击使 FormView 可见的按钮后可见并验证,但我收到 500 错误。
解决方案
推荐阅读
- docker - 连接到上游 Nginx Docker 时连接被拒绝
- javascript - 如何使用 express 显示来自多个不同目录的网页
- ocr - tesseract OCR 无法识别这些数字
- c++ - 当您计算序列中的最大值时,将最大数作为输入的目的是什么?
- javascript - 填写表格后如何获得感谢?
- reactjs - 即使传入了正确的道具,简单的 React 测试也会失败
- html - 如何解决 div 对齐问题?
- c++ - 使用#define 有条件地定义宏
- date - 如何在 Redshift 中结合演员表和日期最大值?
- python - 如何计算呼叫中心的接线员数量?python上的Erlang计算器