Validating TextBox in Form
I am validating textbox1 of below attached project, but i am getting error. Please check it.
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.
Iftikar HussainPosted Aug 11, 2013, 10:26 AM
Regards,
Iftikar
Iftikar HussainPosted Aug 11, 2013, 1:21 PM
http://www.c-sharpcorner.com/uploadfile/mahesh/maskedtextbox-in-C-Sharp/
Regards,
Iftikar
Preeti AgrawallaPosted Aug 11, 2013, 1:17 PM
Preeti AgrawallaPosted Aug 11, 2013, 8:50 AM
Satyapriya NayakPosted Aug 11, 2013, 8:11 AM
Preeti AgrawallaPosted Aug 11, 2013, 5:56 AM
Anurag SarkarPosted Aug 10, 2013, 2:08 PM
{
if (char.IsDigit(e.KeyChar) || char.IsControl(e.KeyChar))
{
e.Handled = false;
}
else
{
e.Handled = true;
}
}
You should try to this code.
Iftikar HussainPosted Aug 10, 2013, 11:59 AM
Try like this
this.textBox1.KeyPress += new KeyPressEventHandler(this.textBox1_KeyPress);
Regards,
Iftikar
Preeti AgrawallaPosted Aug 10, 2013, 11:35 AM
Anurag SarkarPosted Aug 10, 2013, 7:58 AM
private void button2_Click(object sender, EventArgs e)
{
if (textBox3.Text == "")
{
this.errorProvider1.SetError(textBox3, "This Cannott be Blank");
return;
}
if (textBox4.Text == "")
{
this.errorProvider1.SetError(textBox4, "This Cannott be Blank");
return;
}
int s1, s2, s3;
string s;
s1 = Convert.ToInt32(textBox3.Text);
s2 = Convert.ToInt32(textBox4.Text);
s3 = s1 + s2;
s = Convert.ToString(s3);
frmTest2 myObjViewer = new frmTest2();
// hiding the first form.
this.Hide();
myObjViewer.Controls["label2"].Text = s;
// displaying the second form
myObjViewer.ShowDialog();
}
Just run the application you will get the result.
While you will be creating new project you need to drag a error provide control from the toolbox.
Have a look at the sample.
Preeti AgrawallaPosted Aug 10, 2013, 7:37 AM
Anurag SarkarPosted Aug 10, 2013, 7:35 AM
Anurag SarkarPosted Aug 10, 2013, 7:34 AM
Preeti AgrawallaPosted Aug 10, 2013, 7:33 AM
Preeti AgrawallaPosted Aug 10, 2013, 7:31 AM
http://www.codeproject.com/Articles/13922/Validate-user-input-in-Windows-Forms
But i m getting error.
Anurag SarkarPosted Aug 10, 2013, 7:30 AM
{
if(textBox1.text=""){MessageBox.Show("Enter Number");return;}
if(textBox2.text=""){MessageBox.Show("Enter Second Number");return;}
int s1, s2, s3;
string s;
s1 = Convert.ToInt32(textBox1.Text);
s2 = Convert.ToInt32(textBox2.Text);
s3 = s1 + s2;
s = Convert.ToString(s3);
frmTest2 myObjViewer = new frmTest2();
// hiding the first form.
this.Hide();
myObjViewer.Controls["label2"].Text = s;
// displaying the second form
myObjViewer.ShowDialog();
}
Just Put this Code in your form 1.