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 613485
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T18:00:30+00:00 2026-05-13T18:00:30+00:00

I have a gridview with three columns of textboxes. It can have as many

  • 0

I have a gridview with three columns of textboxes. It can have as many rows as necessary but its usually only about 5 rows. Each row needs to be validated.

I want to create a client side validator that sums 2 of the columns together and compares it with the third column to check that the user has entered the data correctly.

Just in case you are wondering, it’s part of the spec that the operator must enter the third column rather than simply summing the two previous columns together in the code behind. This is done to ensure the operator is transcribing the information correctly.

I am trying to use the custom validator in .net to create this client side validation. but I can’t find a way to pass to it the names of the three text boxes.
I can give it the target controls name using the ControlToValidate parameter, but how do I pass in the other two control id’s ?

I am looking for the ‘proper’ way to do this, one thought is to create an array in javascript referenced by the controltovalidate’s name.

DC

  • 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-13T18:00:30+00:00Added an answer on May 13, 2026 at 6:00 pm

    I solved the problem. not an elegant solution but it works.

    first I placed the code into a div on the page

    <div align="right"><asp:CustomValidator ID="RowValidator" runat="server"
    ErrorMessage="Total of #total# does not equal 1st Preference + Ticket"
    ControlToValidate="Total" ValidateEmptyText="True" 
    ClientValidationFunction="CheckRow" SetFocusOnError="True" EnableClientScript="True"
    enableViewState="False" Display="Dynamic"></asp:CustomValidator></div>
    

    Then I created a JavaScript function…

    function CheckRow(sender,args) {
    // get the name of the control to validate
    try {
        args.IsValid = true;
        ctv = sender.controltovalidate;
    
    // get the data from the other controls
        nt = document.getElementById(ctv.replace('_Total','_NonTicket'));
        t = document.getElementById(ctv.replace('_Total','_Ticket'));
    
        if (nt && t) {
            v1 = Number(nt.value);
            v2 = Number(t.value);
            v3 = Number(args.Value);
            if ((v1 + v2) != v3){
                msg = GetMessage(sender);
                sender.innerHTML = msg.replace("#total#",Number(args.Value));
                args.IsValid = false;
                return false;
            }
       }
    }
    catch (e) {
        // something wrong default to server side validation
    }
    return true;
    }
    

    This is called by the custom validator for each row I use the controltovalidate parameter of the sender to get the name

    then its a matter of a bit of string manipulation to get the names of the other fields.

    Once retrieved you can do what you like, in my case I add and compare. if there is an error the Isvalid flag is cleared and the message is modified to suit.

    The getmessage function is required because I alter the message to give a more meaningful error message

    /*
    get the error message from the validator
    store it so it can be retrieved again
    this is done because the message is altered
    */
    function GetMessage(sender){        
    
    msg = window[sender.id+"_msg"];
    if (!msg){
        msg = sender.innerHTML;
        window[sender.id+"_msg"] = msg;
    }
    return msg;
    }
    

    The getmessage function keeps a copy of the original message so if the user makes a mistake more than once the message can be retrieved in its pristine form, other wise the first time we edit a message we overwrite the placeholder (#total#).

    DC

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

Sidebar

Related Questions

I have gridview which contains 60 rows and each row has 4 radiobutton option
I have a GridView with three Button columns that are set up with images.
I have an ASP.NET GridView that has four columns. The first three are typical
I have an ASP.net GridView that spits out three columns of data: ( OrderNumber,
I have a gridview which displays rows and columns all linked to an sql
I have a grid view with three columns and five rows with text item
I have a GridView with three databound columns, like this: <Columns> <asp:BoundField HeaderText=Type DataField=Type
I have a GridView that displays data on three columns. On the third column
i have made a gridview which has many columns and the editmode , some
I have a gridview which has three columns date, pnl, cumpnl I am able

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.