C# Detect Input In TextBox

Please support our C# advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: May 2009
Posts: 54
Reputation: wingers1290 is an unknown quantity at this point 
Solved Threads: 0
wingers1290 wingers1290 is offline Offline
Junior Poster in Training

C# Detect Input In TextBox

 
0
  #1
Jul 23rd, 2009
Hi, Is it at all possible to detect if a user has inputed text into a text box for example.

  1. if (textbox1.Text == ("detect if text is in textbox")
  2. {
  3. // do something
  4. }
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2,612
Reputation: adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of 
Solved Threads: 465
Moderator
adatapost's Avatar
adatapost adatapost is offline Offline
Posting Maven

Re: C# Detect Input In TextBox

 
0
  #2
Jul 23rd, 2009
Use static variable and TextChange event.
Failure is not fatal, but failure to change might be. - John Wooden
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 3,215
Reputation: sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of 
Solved Threads: 573
Sponsor
sknake's Avatar
sknake sknake is offline Offline
.NET Enthusiast

Re: C# Detect Input In TextBox

 
1
  #3
Jul 23rd, 2009
you can also use:
  1. if (!string.IsNullOrEmpty(textBox1.Text))
  2. {
  3. //Do something
  4. }
Scott Knake
Custom Software Development
Apex Software, Inc.
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 54
Reputation: wingers1290 is an unknown quantity at this point 
Solved Threads: 0
wingers1290 wingers1290 is offline Offline
Junior Poster in Training

Re: C# Detect Input In TextBox

 
0
  #4
Jul 23rd, 2009
This is what i am trying to do
  1. private void button2_Click_1(object sender, EventArgs e)
  2. {
  3. FieldStore();
  4.  
  5. foreach (Control c in panel1.Controls)
  6. {
  7.  
  8. if (!string.IsNullOrEmpty(c.Name = "field1"))
  9. {
  10. MessageBox.Show("Please Enter At Least One Room Or Put Your Rooms In Numeric Order");
  11. }
  12.  
  13. }
  14. }
and so far messageboxes are coming up no matter what is in the dynamically created textboxes, i only want it to pop up if there is something in the textbox.
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 3,215
Reputation: sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of 
Solved Threads: 573
Sponsor
sknake's Avatar
sknake sknake is offline Offline
.NET Enthusiast

Re: C# Detect Input In TextBox

 
0
  #5
Jul 23rd, 2009
Yeah .. you have a bug in your code that will cause it to never evaluate the condition as true.

Try this:
  1. private void button1_Click(object sender, EventArgs e)
  2. {
  3. foreach (Control ctrl in panel1.Controls)
  4. {
  5. TextBox tb = (ctrl as TextBox);
  6. if (tb != null)
  7. {
  8. if (!string.IsNullOrEmpty(tb.Text))
  9. {
  10. tb.Focus();
  11. MessageBox.Show("Please dont type in the text boxes");
  12. tb.Focus();
  13. break;
  14. }
  15. }
  16. }
  17. }
Last edited by sknake; Jul 23rd, 2009 at 8:04 am.
Scott Knake
Custom Software Development
Apex Software, Inc.
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 54
Reputation: wingers1290 is an unknown quantity at this point 
Solved Threads: 0
wingers1290 wingers1290 is offline Offline
Junior Poster in Training

Re: C# Detect Input In TextBox

 
0
  #6
Jul 24th, 2009
thanks thant helps alot but now i'm trying this...
  1. private void button2_Click_1(object sender, EventArgs e)
  2. {
  3. FieldStore();
  4.  
  5. foreach (Control ctrl in panel1.Controls)
  6. {
  7. TextBox tb = ctrl as TextBox;
  8. {
  9. if (tb != null)
  10. {
  11. MessageBox.Show("Error1, Please Enter Areas In Numeric Area And Fill In All Text Boxes");
  12.  
  13. if(!string.IsNullOrEmpty (tb.Text))
  14. {
  15. Form2 form2 = new Form2();
  16. form2.Show();
  17. }
  18. }
  19. }
  20.  
  21.  
  22.  
  23. }
  24. }
but its displaying the error message even if there is text in text box, any ideas?
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 64
Reputation: lighthead is on a distinguished road 
Solved Threads: 15
lighthead's Avatar
lighthead lighthead is offline Offline
Junior Poster in Training

Re: C# Detect Input In TextBox

 
1
  #7
Jul 24th, 2009
You put the message box in the wrong place.
  1. if (tb != null)
  2. {
  3. if(!string.IsNullOrEmpty(tb.Text))
  4. {
  5. Form2 form2 = new Form2();
  6. form2.Show();
  7. }
  8. else
  9. {
  10. //error message goes here...
  11. }
  12. }
Everybody Lies.
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 54
Reputation: wingers1290 is an unknown quantity at this point 
Solved Threads: 0
wingers1290 wingers1290 is offline Offline
Junior Poster in Training

Re: C# Detect Input In TextBox

 
0
  #8
Jul 24th, 2009
Thanks sooo much!
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC