What are some effective ways to utilize customvalidator for performing clientside validation on two input fields?

I attempted to implement a asp:CustomValidator along with client-side JavaScript in order to validate that the user does not input the same new password as the old password using the following code...

    <script type="text/javascript">
    function CustomValidator1_ServerValidate1(source, arguments) {
        var sOldPassword = document.form1.<%= tbOldPassword.ClientID %>.value;
        var sNewPassword = document.form1.<%= tbNewPassword.ClientID %>.value;
        if (sOldPassword == sNewPassword) {
            arguments.IsValid = false;
        } else {
            arguments.IsValid = true;
        }
    }
</script>

<asp:CustomValidator ID="CustomValidator1" runat="server" 
                     ErrorMessage="Old and new password cannot be the same"

                     ClientValidationFunction="CustomValidator1_ClientValidate1"
                     ValidateEmptyText="True" ValidationGroup="Custom"></asp:CustomValidator>

Unfortunately, this implementation is not functioning correctly. Can anyone identify why it is not working?

Answer №1

After troubleshooting, I discovered the problem stemmed from using document.getElementById in the JavaScript instead.

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

How to utilize the index in a foreach loop as a variable in JavaScript

I am facing an issue with using the index of a forEach loop to access an array index in my code. It seems to work when I use a number directly, but not when I try to use the index variable. Any suggestions or insights on how to resolve this? let post ...

Learn how to easily modify a value in a CVS file by simply clicking on the data point on a highcharts graph

Is there a way to update my CSV file by clicking on a graph? I want to be able to create a graph from data in the same CSV file and then, when I click on a point, set that point to zero on the y-axis and update the corresponding value in the CSV file to 0. ...

Guide for integrating images in React Native

I am struggling to display images in a carousel properly. I attempted to require them using JSON like this {"Image": require("$PATH")} or in a js file within the ParallaxImage tag, but nothing seems to work... Item Creator _renderItem ...

Create cookie without reloading webpage

Upon a user's initial visit to a specific page, I am displaying a jQuery overlay. The overlay includes a radio button that users can click to indicate they do not want to see the notification again. I am interested in setting a cookie to track users ...

Exploring the paths with node.js variable walking

Currently facing an issue with the npm package "walk". The problem lies in the fact that it requires a string to define the path, which poses difficulty as the path varies based on the directory to be searched. var walkers = walk.walk(""+animeDir+"", opti ...

What should I do if one of my images fails to load after the previous one has loaded successfully?

My code is designed to create an animation using 3 canvases: one for the base image, one for the streamline wind map drawing, and another for an image covering part of the drawing. The following code displays the uploading of two images. var im ...

Is the absolute positioned element on the left or right based on its current location?

Is there a way to assign absolute positioning with left at 0px or right at 0px depending on whether the positioned div will go outside of its container? For example, when you right click in a browser and see the menu appear to the right of where you click ...

Arranging the columns of a matrix

My dilemma involves a matrix (or multidimensional array) filled with non-unique values, similar to this example: var matrix = [ [1, 3, 2, 4, 1], [2, 4, 1, 3, 2], [4, 3, 2, 1, 4] ] I am in need ...

Solving the Issue of Assigning a Random Background Color to a Dynamically Created Button from a Selection of Colors

Trying to create my own personal website through Kirby CMS has been both challenging and rewarding. One of the features I'm working on is a navigation menu that dynamically adds buttons for new pages added to the site. What I really want is for each b ...

Is there a way to pre-load the data prior to the component rendering in ReactJS?

The main goal of my project is to retrieve data from the Google Analytics API and display it as a list. Although I am able to successfully fetch the data from the API, I am encountering an issue when passing it to another component. While I can view the da ...

When it comes to utilizing the method ".style.something" in JavaScript

Here is some javascript code that I am working with: function createDiv(id){ var temp = document.createElement('div'); temp.setAttribute("id", id); document.getElementsByTagName('body')[0].appendChild(temp); } c ...

Designing a personalized look for a property with Styled-System

Styled-System offers various props related to css grid: I have a suggestion for a new prop, gridWrap. My idea is to allow users to adjust the auto-fit value using the gridWrap prop. Here's the base CSS code: grid-template-columns: repeat(auto-fit, mi ...

What could be causing my function to exclude only the final element of the array when it returns?

My goal with the following code is to retrieve all items from item.children. However, I am puzzled as to why it's not returning the last item. After conducting multiple result logs and SQL verifications, I eventually pinpointed the issue in a specific ...

Response from Socket.io: What is the best way for the server to respond to all clients after receiving input from multiple clients?

Currently diving into the realm of node.js, express, and socket.io Thrilled to report that my server is up and running, successfully connecting to the browser via localhost:3000 Communication between client and server is seamless both ways. Now, onto th ...

Showing nested arrays in API data using Angular

I would like to display the data from this API { "results": [ { "name": "Luke Skywalker", "height": "172", "mass": "77", & ...

Encountering issues with accessing a closed stream in ASP.net version 2.0

We are facing a strange issue. The code below is functioning perfectly on all developer machines and our two test servers, both in code and built versions. However, when it runs on a virtual machine with Windows 2003 Server and ASP.NET v2.0, it throws an e ...

Are there benefits to using AngularJS for a basic AJAX site?

After creating a basic website, I have decided to enhance it with a JavaScript overlay for various functionalities such as: Implementing ajax in the search box and pagination for seamless loading of results without refreshing the page Integrating the HTM ...

The Angular controller that has been injected into the app is not defined

In an effort to enhance my simple Angular app, I decided to modularize it. I separated the controller into its own file within a dedicated directory. By employing dependency injection, I ensured the controller's availability in the app module. Combini ...

Regular and Novel entries in Dataset Table

Currently, I am dealing with two separate dataTables: 1) dtExistingZipCodeInDB (which contains data from the database) 2) dtCSVExcelSource (where the data is sourced from a CSV file and needs to be processed) There are two specific requirements that I n ...

Issue with body element displacement when utilizing Bootstrap 5.2 toast component

While utilizing a Bootstrap 5 toast, I noticed that it causes the entire body to shift down. I suspect that there may be an issue with how I am handling relative and absolute positioning attributes, but I am uncertain. This is my first time using Stack Ove ...