Take the 2-minute tour ×

I have 81 RichTextBoxes in my form (Sudoku Solver), and I would like them to turn gray when user inputs data into them and when there is no data (for example ereased or never was there) to stay white. How do I manage that?

share|improve this question
show us what did you have tried. –  Prashant16 Jun 24 '13 at 9:27
u can use jquery validate plugin. check if it is empty or filled then change colour –  Zaki Jun 24 '13 at 9:27
@Sam This is C#. I have a feeling jQuery is not an option (hate to break it to you, but JS/DOM isn't everywhere). –  michaelb958 Jun 24 '13 at 9:39
@michaelb958 my bad miss-read the tag thought it is asp.net :) –  Zaki Jun 24 '13 at 10:06

2 Answers 2

up vote 2 down vote accepted

Use an EventHandler!

private void TextChangedEventHandler(object sender, EventArgs e)
   TextBox tb = sender as TextBox;
   if(tb != null){
       if(tb.Text.Length > 0){
        //set color
         //set color


//Loop through your controls (textboxes) and set handler

foreach(Control c in this.Controls){

    if(c is TextBox){
        c.TextChanged += TextChangedEventHandler;

share|improve this answer
+1 And loop through the textboes to add them instead of rewriting the adding line 81 times ;) –  Yami Jun 24 '13 at 9:29
@Yami Of course^^ Would take years to do so... –  bash.d Jun 24 '13 at 9:30
Thanks a lot :) –  Kamilczak020 Jun 24 '13 at 12:53
@user2515638 You are welcome :) Please accept as answer if it helped you! –  bash.d Jun 24 '13 at 13:51
$(".test").on("change keyup paste click", function()  {        


this.css('background-color', '#ffff00');


     this.css('background-color', '#ffff55');
share|improve this answer
-1 As I said to @Sam in the question comments, this is C#, and there is no JavaScript/DOM in sight, so jQuery is not an option. –  michaelb958 Jun 24 '13 at 10:07

Your Answer


