当 JS 被禁用时,我试图在服务器端验证 ASP.NET BasicDatePicker 控件,但似乎无法触发事件。
有 JS 验证(使用 .NET 验证器),但我们仍然收到使用无效日期的批量搜索。这表明垃圾邮件机器人或其他僵尸网络正在绕过 JavaScript 验证。我们使用 FF 插件禁用 JavaScript 以测试该字段是否经过验证,但回发事件似乎没有触发。
代码如下,任何帮助将不胜感激。
ASP.NET ASPX 页面
<div align="center">
{EXTRA MARKUP REMOVED}
<asp:Label ID="Label3" runat="server" Text="<%$ Resources:words, Arrival_Date %>"></asp:Label>
<BDP:DateRangeValidator ID="DateRangeValidator1" runat="server" ErrorMessage="DateRangeValidator"
ControlToValidate="datefrom" Text="**"></BDP:DateRangeValidator><BDP:IsDateValidator
ID="IsDateValidator2" runat="server" ErrorMessage="IsDateValidator" ControlToValidate="datefrom"
Text="*"></BDP:IsDateValidator><br />
<BDP:BDPLite ID="datefrom" runat="server" TextBoxColumns="12" />
<hlp:popup ID="popup4" runat="server" contextid="hlp_arrivaldate" />
{EXTRA MARKUP REMOVED}
<asp:Button ID="Button1" runat="server" Font-Size="11px" Text="<%$ Resources:words, Search %>"
UseSubmitBehavior="False" OnClick="Button1_Click" />
<div style="padding-bottom: 5px">
<asp:Label ID="serverErrorMessage" runat="server" Visible="false" />
</div>
</div>
BUTTON1_CLICK 事件(似乎没有触发)
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
'check for stuff in the date field
If InStr(Me.datefrom.ToString, "http") > 0 Then Exit Sub
If InStr(Me.datefrom.ToString, "//") > 0 Then Exit Sub
If InStr(Me.txtPropertyLike.ToString, "http") > 0 Then Exit Sub
If InStr(Me.txtPropertyLike.ToString, "//") > 0 Then Exit Sub
'test the date, and exit if not valid
Dim datetest As Date = CDate("01-Jan-2001")
Try
datetest = CDate(Me.datefrom.SelectedDate)
If datetest < Today Or DateDiff(DateInterval.Year, Today, datetest) > 2 Then
datetest = CDate("01-Jan-2001")
End If
Catch
End Try
If datetest = CDate("01-Jan-2001") Then
serverErrorMessage.Text = "Date be within the next 2 calendar years."
serverErrorMessage.Visible = True
Exit Sub
End If
End Sub
我知道这可能很愚蠢。只是不知道是什么,因为我已经没有头发了,所以没有可以拔掉的。:(
杰格