Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 557697
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T12:03:14+00:00 2026-05-13T12:03:14+00:00

Here is a code for my web form control <asp:TextBox runat=server ID=txtUsername></asp:TextBox> <asp:RequiredFieldValidator ID=RequiredFieldValidator1

  • 0

Here is a code for my web form control

<asp:TextBox runat="server" ID="txtUsername"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" ControlToValidate="txtUsername" runat="server" ErrorMessage="RequiredFieldValidator"></asp:RequiredFieldValidator>
<asp:CustomValidator OnServerValidate="checkUsername" ID="CustomValidator1" runat="server" ControlToValidate="txtUsername" EnableClientScript="true" ClientValidationFunction="checkUsername" ErrorMessage="CustomValidator"></asp:CustomValidator>

Client side validation

<script type="text/javascript">
        function checkUsername(source,args){
        alert("test");
           /* alert(args.Value);
            args.IsValid=false;
            */
        }
    </script>

Server side validation

protected void checkUsername(object sender, System.Web.UI.WebControls.ServerValidateEventArgs e) {
            String str=e.Value;
            if(str.Length>6)
            e.IsValid = false;
        }

But for some reason this Costom Validation is not firing . Any clues ?

EDIT:
I am coding in asp for first time , Server validation is in code-behind class

Here is a code asp.net page , Maybe some small mistake I am making ?

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Registration.aspx.cs" Inherits="lab1.Registration" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>

        <asp:Button ID="Button1" runat="server" Text="Recreate table" 
            onclick="Button1_Click" />
        <asp:GridView ID="GridView1" runat="server">
        </asp:GridView>

    </div>
    <script type="text/javascript">
        function checkUsername(source,args){
        args.IsValid=(args.Value.length<=6);
           /* alert(source.Value);
            args.IsValid=false;
            alert(document.getElementById("txtUsername").nodeValue);*/
        }
    </script>
    <asp:Table ID="Table1" runat="server" Height="106px" Width="469px">

        <asp:TableRow>
            <asp:TableCell>
                <asp:Label runat="server" Text="Username"></asp:Label>
            </asp:TableCell>
            <asp:TableCell>
                <asp:TextBox runat="server" ID="txtUsername"></asp:TextBox>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator1" ControlToValidate="txtUsername" runat="server" ErrorMessage="RequiredFieldValidator"></asp:RequiredFieldValidator>
                <asp:CustomValidator OnServerValidate="checkUsername" ID="CustomValidator1" runat="server" ControlToValidate="txtUsername" EnableClientScript="true" ClientValidationFunction="checkUsername" ErrorMessage="CustomValidator"></asp:CustomValidator>

            </asp:TableCell>
        </asp:TableRow>

    </asp:Table>

    </form>
</body>
</html>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T12:03:14+00:00Added an answer on May 13, 2026 at 12:03 pm

    Ok, try changing your two methods like this.

    <script type="text/javascript"> 
        function checkUsername(source,args){    
            args.IsValid=(args.Value.length<=6);
        }
    </script>
    

    and

    protected void checkUsername(object sender, System.Web.UI.WebControls.ServerValidateEventArgs e)
    {
        e.IsValid = (e.Value.Length <= 6);
    }
    

    The only real difference is it works out the true and the false IsValid, rather than only setting it to false.

    If this isn’t the problem then please elaborate a bit more on exactly what isn’t working.

    EDIT: Just to add to this… If it’s just a length of input that you’re interested then why not use a RegularExpressionValidator?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using the obsolete System.Web.Mail sending email works fine, here's the code snippet: Public Shared
Here's the idea: you commit your code to a repository and call a web
I am trying to add a TextBoxWatermarkExtender control into my ASP.NET 3.5 web application.
How do I go about rendering an asp.net control on a web page from
Edit: The code here still has some bugs in it, and it could do
See here: http://code.google.com/p/ie7-js/ Does anyone have any experience or remarks about this javascript? Is
I have this code here: var infiltrationResult; while(thisOption) { var trNode = document.createElement('tr'); var
We have some old C code here that's built with nmake. Is there an
I am using pseudo-code here, but this is in JavaScript. With the most efficient
I have a piece of code here that i really could use some help

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.