Click here to Skip to main content
12,701,854 members (34,298 online)
Rate this:
Please Sign up or sign in to vote.
See more: ASP.NET
Hey friends,

I have two validators on my textboxes.
The TxtPassword has 2 validators:

1.Asp.Net RequiredField Validator.
2.Password length implemented by me with JavaScript.

both are bound to button.

My problem is that...

Whenever i enter the password greater than 20 characters..everything works fine.
But when i leave the TxtPassword empty,the Client side script is bypassed.Sure this is correct.But my Required field validator doesnt work and control flows to server side.and i redirect to other page.

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="LoginPage.aspx.cs" Inherits="LoginPage" %>

<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="asp" %>
Posted 3-Feb-13 21:16pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

use regular expression intead of javascript,
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Add another validator to the text box

<asp:CustomValidator runat="server"

Also update your javascript function

function checkforlength(sender, args) {
    if (args.Value.length > 20) {
        alert("password exceeded the range");
        return false;
    else {return true;}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.170118.1 | Last Updated 4 Feb 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100