Issue with server side validation not triggering when JavaScript is turned off

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" />
    &nbsp;<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

Answer №1

From my perspective, utilizing Page.IsValid should help in resolving the issue at hand.

Here's an example:

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
if (Page.IsValid)
   {
    // your code 
   } else {
   // display some error message to the user 
  }

In order for this property to return true, all validation server controls within the current validation group must pass successfully.

Please let me know if this resolves your problem. I am here to assist :)

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The viewport width in NextJS does not extend across the entire screen on mobile devices

I'm currently tackling a challenge with my NextJS Website project. It's the first time this issue has arisen for me. Typically, I set the body width to 100% or 100vw and everything works smoothly. However, upon switching to a mobile device, I not ...

Timer for searching webpages using Javascript

I am looking for a way to continuously search a specific webpage for a certain set of characters, even as the text on the page changes. I would like the program to refresh and search every minute without having to keep the webpage open. In addition, once ...

"Arranging the categories on the xAxis in highcharts based on total values - a step

Is it possible to sort this highchart chart by total? View the highchart chart here The desired final output would be: Name 1 -> 19 Name 4 -> 12 Name 3 -> 10 Name 2 -> 8 See the code snippet below: $(function () { $('#contain ...

Instantly create forms with ASP.NET MVC on your website

Are there any open source form builders available that can be seamlessly integrated into my MVC project to allow users to create forms dynamically? I envision a scenario where users have the ability to design their own forms, which can then be rendered by ...

Upon transmitting the information to the server, an error message pops up saying 'Uncaught TypeError: Illegal invocation'

I'm encountering an issue with sending an ajax request in my php-script. The jquery script I'm using selects certain fields from a form and sends them as arguments to a jquery function. However, upon sending the data to the server, I receive the ...

Angular JS: Implementing a click event binding once Angular has completed rendering the HTML DOM

Exploring AngularJS for the first time, I've researched extensively but haven't found a satisfying solution. My goal is to retrieve data from the server and bind it to HTML elements on page load. However, I also need to bind click events to these ...

Several attributes in the JSON object being sent to the MVC controller are missing or have a null

I am facing an issue while passing a JSON object to my MVC controller action via POST. Although the controller action is being called, some elements of the object are showing up as NULL. Specifically, the 'ArticleKey' element is present but the & ...

Sending a JavaScript array to a Ruby on Rails controller by utilizing a hidden form field

Having explored numerous solutions that did not fit or resolve my issue, I am turning to this platform with my question: I utilize JavaScript to populate hidden fields in a form with data and transmit it to a Ruby on Rails controller. While this process w ...

Which variables are accepted in the HTML <script> language?

<script type="text/JavaScript1.2" ... <script type="text/JavaScript" ... Do these script declarations impact the way JavaScript is executed? ...

Steps for dynamically applying a CSS class to items within an ASP.NET CheckBoxlist in an HTML table

Is there a way to dynamically apply CSS classes to ASP.NET CheckBoxlist HTML table elements programmatically? For instance, I would like the "table", "tr", and "td" tags in the output below (as seen in the browser View Source) to include CSS styles. < ...

Tips on editing a file exclusively when a specific requirement is fulfilled

Looking for a way to implement a put method within an Express API that allows users to update a document conditionally? Consider this scenario: you have an Instance document with an attribute called executed, which is set to true if the instance has been e ...

Designing Games with Matrix Elements

Greetings to the StackOverflow Community! Currently, I am working on developing a JavaScript version of the well-known game Pentago as a personal side project before resuming my studies in the fall. However, I have hit a roadblock and need some guidance o ...

Unit testing a React component by using the `renderToString` method

Context My React application is built using the React Starter Kit. In the server.js file, components are rendered using renderToStaticMarkup and then passed to the Html component, which includes it using dangerouslySetInnerHTML as shown here. I am facing ...

Using ng-repeat with deeply nested objects

I am facing an issue with rendering an object that contains comments along with replies objects that have nested replies objects. I attempted to use a solution from here, but it resulted in my replies object being undefined. For example, I tried the follow ...

Having trouble with binding complex form data posted from AngularJS to ASP.Net Web API 2

I'm currently experimenting with some demo examples to learn how to properly transfer form data from an Angular Service to a Web API 2 controller POST action. However, I am encountering an issue where my object always turns out to be null on the contr ...

Creating a new item in Angular 2 using user input

Just dipping my toes into Angular2 and attempting to append a new item to the list through input. However, upon clicking submit, instead of text I get [object Object]. Check out the code snippet below: app.component.html <form (submit)="addItem(item) ...

Asyncronous calls in Angular involve executing tasks without

The issue seems to be related to the timing of updates for the controlSelected and isAssessmentDataLoading variables. The updateQuestions() method is invoked within the ngOnInit() method, which is triggered when the component is initialized. However, the ...

Error: The program encountered a type error while trying to access the '0' property of an undefined or null reference

I am a beginner in the world of coding and I am currently working on creating an application that allows users to add items to their order. My goal is to have the quantity of an item increase when it is selected multiple times, rather than listing the same ...

Expandable menu using jQuery

Currently, I am experimenting with an Accordion Menu plugin called example 3: Non-accordion (standard expandable menu). My goal is to set up a menu structure where there are 5 options. Two of these options have sub-menus, while the other three are direct ...

Sending PHP form data to Google Chart via AJAX

After creating a PHP form drop-down list of table names in a database that captures the user's selection, I aim to use that selected table name to generate a Google chart. However, I'm encountering difficulties in passing the variable through AJA ...