I am facing an issue with validating an ASP.NET BasicDatePicker Control on the server side when JavaScript is disabled. The event does not seem to trigger as expected.
Despite having JS Validation in place using .NET Validators, we are still seeing searches with invalid dates, which indicates that there might be a spambot or botnet bypassing the JavaScript validation. We have even tested by disabling JavaScript using FF addons to check if the field gets validated, but the postback event does not fire.
Below is the code snippet, any assistance would be highly appreciated.
ASP.NET ASPX PAGE
<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 EVENT (DOES NOT SEEM TO FIRE)
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
I'm sure it's probably something simple. Just can't seem to identify the problem, and I already have no hair left to pull out over this. :(
JGe