How can I pass empty textboxes
I have 5 textbox. I want to put all 4 textbox text in 5th textbox. I can do it, but when any textbox was null ,I had an error. Some textboxes will be empty. How can I do this without error.
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Amar SrivastavaPosted Sep 15, 2017, 2:12 AM
Subhashkumar YadavPosted Dec 16, 2016, 7:14 AM
Gowtham RajamanickamPosted Apr 5, 2015, 11:23 PM
VulpesPosted Mar 28, 2015, 2:51 PM
Otherwise it's default value is an empty string and so this will be the value it has if the user doesn't fill it.
To allow for that possibility or that the user may fill the TextBox with several spaces, try the following code instead:
Pankaj Kumar ChoudharyPosted Mar 28, 2015, 1:48 PM
textBox5.Text = (textBox1.Text.Length > 0) ? textBox1.Text : " " ;
textBox5.Text += (textBox2.Text.Length > 0) ? textBox1.Text : " " ;
textBox5.Text += (textBox3.Text.Length > 0) ? textBox1.Text : " " ;
textBox5.Text += (textBox4.Text.Length > 0) ? textBox1.Text : " " ;
textBox5.Text=textBox5.Text.Trim();
Artur Vahe KarapekmezPosted Mar 28, 2015, 1:39 PM
VulpesPosted Mar 28, 2015, 1:22 PM
string temp = (Textbox1.Text == null) ? "" : TextBox1.Text + " ";
temp += (Textbox2.Text == null) ? "" : Textbox2.Text + " ";
temp += (Textbox3.Text == null) ? "" : Textbox3.Text + " ";
temp += (Textbox4.Text == null) ? "" : Textbox4.Text;
Textbox5.Text = temp.Trim();
Artur Vahe KarapekmezPosted Mar 28, 2015, 12:52 PM
Khargesh RajputPosted Mar 28, 2015, 12:41 PM
Textbox2.text=" ";
Artur Vahe KarapekmezPosted Mar 28, 2015, 12:12 PM
My question is for example;
Textbox1.Text ="Hello";
Textbox2.Text =null;
Textbox3.Text ="World";
Textbox4.Text = null;
when textboxes like that;
Textbox5.Text= Hello World;
How can I do This.(Not allways Textbos2 and 4 will be null it will be empty according to users but at least 1 textbox will be not null.
Afzaal Ahmad ZeeshanPosted Mar 28, 2015, 12:01 PM
if(textBox1.Text != null && textBox2.Text != null && textBox3.Text != null) {
// value is not null
}
I have tested only 3, you can add the fourth condition too. This way, the code would only execute if the value is not null, I am using AND operator. Which evaluates only and only if all of the conditions are true.