A question about asp.net Validator

Discussion in 'ASP General' started by Nicky, Jan 18, 2005.

  1. Nicky

    Nicky Guest

    I am new on asp.net programming.
    Here I got a problem about validator
    I want to write a login.aspx page, for example, there is UserName box. I
    need to validate two things on UserName box,
    1. It must be filled. If it is empty, I will show a red message right after
    this box, like "UserName is empty!"
    2. It must be a valid user in our database. So on server side, we will check
    this UserName in our database. If it is not in our database, we will show
    something like "Invalid user name..."
    I know it is very easy to do the 1st rule with the RequireFieldValidator.
    But in order to do the rule 2, I need to put a Lable at the same place where
    the validator is. Right? But the two won't stay at the same place. So I tried
    to use a CustomValidator, and write the ClientValidationFunction like this:
    <script language="javascript">
    function ValidUserName(oSrc, args) //For rule 1
    {
    if(args.Value.length > 0)
    args.IsValid = true;
    else
    args.IsValid = false;
    }
    </script>
    And also, I have a server validate function which will process the rule 2.
    But the problem is the client validate function never get called. So , do
    you guys have better solution for this? I really appreciated.
     
    Nicky, Jan 18, 2005
    #1
    1. Advertising

  2. Hi Nicky,

    it's probably best to direct ASP.NET questions to
    microsoft.public.dotnet.framework.aspnet rather than to this group, which is
    'classic' ASP focussed. You'll get a pretty quick answer there.


    --
    Jason Brown
    Microsoft GTSC, IIS

    This posting is provided "AS IS" with no warranties, and confers no
    rights.

    "Nicky" <> wrote in message
    news:...
    >I am new on asp.net programming.
    > Here I got a problem about validator
    > I want to write a login.aspx page, for example, there is UserName box. I
    > need to validate two things on UserName box,
    > 1. It must be filled. If it is empty, I will show a red message right
    > after
    > this box, like "UserName is empty!"
    > 2. It must be a valid user in our database. So on server side, we will
    > check
    > this UserName in our database. If it is not in our database, we will show
    > something like "Invalid user name..."
    > I know it is very easy to do the 1st rule with the RequireFieldValidator.
    > But in order to do the rule 2, I need to put a Lable at the same place
    > where
    > the validator is. Right? But the two won't stay at the same place. So I
    > tried
    > to use a CustomValidator, and write the ClientValidationFunction like
    > this:
    > <script language="javascript">
    > function ValidUserName(oSrc, args) //For rule 1
    > {
    > if(args.Value.length > 0)
    > args.IsValid = true;
    > else
    > args.IsValid = false;
    > }
    > </script>
    > And also, I have a server validate function which will process the rule 2.
    > But the problem is the client validate function never get called. So , do
    > you guys have better solution for this? I really appreciated.
     
    Jason Brown [MSFT], Jan 18, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. coollzh
    Replies:
    0
    Views:
    382
    coollzh
    Jun 3, 2004
  2. Bobby
    Replies:
    2
    Views:
    525
    Peter Blum
    Jul 9, 2004
  3. BillGatesFan
    Replies:
    2
    Views:
    571
    BillGatesFan
    Nov 4, 2005
  4. spidur1

    ASP.Net 2.0 required field validator.

    spidur1, Nov 9, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    6,867
    Bruce Barker
    Nov 9, 2005
  5. Replies:
    4
    Views:
    908
    Richter~9.6
    Feb 13, 2007
Loading...

Share This Page