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

  • Home
  • SEARCH
  • 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 7622635
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T04:30:08+00:00 2026-05-31T04:30:08+00:00

I am creating some text boxes at runtime and I would like to change

  • 0

I am creating some text boxes at runtime and I would like to change the color of the text box if the text box has been left blank
and the user submits the form.

I am using the code behind approach, this is the code I wrote in the .aspx.cs file

textBoxObj is the text box object that I create at runtime and it is the object on which I want the empty validation.

CustomValidator customValidatorObj = new CustomValidator();
customValidatorObj.ControlToValidate = textBoxObj.ID;
customValidatorObj.ClientValidationFunction = "changeColorofTextBox";

and I wrote a small Javascript snippet within the .aspx file which goes as follows (I haven’t yet written the logic to change the color,
just making it not valid for now)

<script type="text/javascript">
    function changeColorofTextBox(oSrc, args) {
        if (args.Value.length > 0) {
            args.IsValid = true;
        }
        else {
            args.IsValid = false;
        }
    }
</script>   

In the submit button click function of the form, I have this check if(Page.IsValid), then submit the form. However, even when the text box is empty,
the form gets submitted. It seems like the function is not even being hit. Do you have any pointers on what I am doing wrong?
I am fine with either client side or server side validation, whichever works.

EDIT

I got the error, I just had to do this

customValidatorObj.ValidateEmptyText = true;

and it started working.. Thank you, I didn’t realize that the customValidator class does not try validating if the control is blank.

But I am stuck again 🙁

In the form, I have many text boxes. Suppose, the user entered text for 3 of the text boxes and left 2 of them blank, how do I find the text box ids so that I can change the color of only the blank ones. or, how can I write code in the javascript to find out the control ID at runtime?

I know we have to do this

document.getElementById(CONTROLIDGOESHERE).style.backgroundColor = “red”;

but how I get the CONTROLIDGOESHERE value to pass to the getElementById function?

Any pointers, thanks.

  • 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-31T04:30:10+00:00Added an answer on May 31, 2026 at 4:30 am

    Try setting customValidatorObj.EnableClientScipt = True

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

Sidebar

Related Questions

I'm creating some text boxes on my form programmatically which I need to reference
I am creating some build scripts that interact with Perforce and I would like
Creating some simple html pages specific for the iphone, and would like to use
I am creating a custom text box control to have some default formatting and
I'm creating a basic forum where every message contains the authors name, some text
I am creating a site with lots of big scrollable text-boxes in it. Each
I'm creating some images of text in code that need to reflect a CSS
I am creating an address control which would use some address validation APIs( google/bing
I am creating some xsl to transform my xml into text (which will be
I am creating a CMS with codeigniter and need to store some text that

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.