| | |
C# Detect Input In TextBox
Please support our C# advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: May 2009
Posts: 54
Reputation:
Solved Threads: 0
Hi, Is it at all possible to detect if a user has inputed text into a text box for example.
C# Syntax (Toggle Plain Text)
if (textbox1.Text == ("detect if text is in textbox") { // do something }
you can also use:
c# Syntax (Toggle Plain Text)
if (!string.IsNullOrEmpty(textBox1.Text)) { //Do something }
•
•
Join Date: May 2009
Posts: 54
Reputation:
Solved Threads: 0
This is what i am trying to do
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.
C# Syntax (Toggle Plain Text)
private void button2_Click_1(object sender, EventArgs e) { FieldStore(); foreach (Control c in panel1.Controls) { if (!string.IsNullOrEmpty(c.Name = "field1")) { MessageBox.Show("Please Enter At Least One Room Or Put Your Rooms In Numeric Order"); } } }
Yeah .. you have a bug in your code that will cause it to never evaluate the condition as true.
Try this:
Try this:
c# Syntax (Toggle Plain Text)
private void button1_Click(object sender, EventArgs e) { foreach (Control ctrl in panel1.Controls) { TextBox tb = (ctrl as TextBox); if (tb != null) { if (!string.IsNullOrEmpty(tb.Text)) { tb.Focus(); MessageBox.Show("Please dont type in the text boxes"); tb.Focus(); break; } } } }
Last edited by sknake; Jul 23rd, 2009 at 8:04 am.
•
•
Join Date: May 2009
Posts: 54
Reputation:
Solved Threads: 0
thanks thant helps alot but now i'm trying this...
but its displaying the error message even if there is text in text box, any ideas?
C# Syntax (Toggle Plain Text)
private void button2_Click_1(object sender, EventArgs e) { FieldStore(); foreach (Control ctrl in panel1.Controls) { TextBox tb = ctrl as TextBox; { if (tb != null) { MessageBox.Show("Error1, Please Enter Areas In Numeric Area And Fill In All Text Boxes"); if(!string.IsNullOrEmpty (tb.Text)) { Form2 form2 = new Form2(); form2.Show(); } } } } }
You put the message box in the wrong place.
C# Syntax (Toggle Plain Text)
if (tb != null) { if(!string.IsNullOrEmpty(tb.Text)) { Form2 form2 = new Form2(); form2.Show(); } else { //error message goes here... } }
Everybody Lies.
![]() |
Similar Threads
- How to pass the input of a textbox in Form1 onto Form2? (C++)
- searching by multiple user input and display output in textbox and picture box (VB.NET)
- Input from textbox!! (VB.NET)
- How to detect input in textbox? (ASP.NET)
Other Threads in the C# Forum
- Previous Thread: for those records in SQL database, gridview checkbox remains checked
- Next Thread: Data Encryption and Decryption
| Thread Tools | Search this Thread |
.net access algorithm array barchart bitmap box broadcast buttons c# check checkbox client combobox control conversion csharp custom cyclethruopenforms data database datagrid datagridview dataset datetime degrees development draganddrop drawing encryption enum event excel file finalyearproject form format forms function gdi+ getoutlookcontactusinfcsvfile globalization httpwebrequest image index input install installer java label list listbox mandelbrot math mono mouseclick mysql operator panel path photoshop picturebox pixelinversion post programming radians regex remote remoting richtextbox save server silverlight sleep socket sql sql-server statistics stream string table text textbox thread time timer timespan update upload usercontrol users validate validation visualstudio webbrowser wia windows winforms wpf xml






