Hi all,
I have a textbox which i wrote Convert.toint32(txtbox.text) which takes phone no.
Suppose i want to pass blank textbox it throws an error that input string is not in correct format.
i have a requirement that the textbox can be blank.
hope i may get a solution.
Thanks in advance
Vijay
Loading
VulpesPosted Feb 29, 2012, 4:51 AM
If the phone number is blank or invalid, you could then set this variable to null:
string t = textBox1.Text.Trim();
int? phoneNumber = null;
if (t != "")
{
int temp;
if(int.TryParse(t, out temp)) phoneNumber = temp;
}
SenthilkumarPosted Feb 29, 2012, 1:43 AM
int i;
bool result = int.TryParse(textBox1.Text, out i);
if (result)
{
i = Convert.ToInt32(textBox1.Text);
}
Because the value can be null or string or alphanumric.
If it is useful then mark it as accepted answer.
Satyapriya NayakPosted Feb 28, 2012, 11:41 PM
private void button1_Click(object sender, EventArgs e)
{
if (textBox1.Text == "")
{
MessageBox.Show("Insert Phone no");
}
else
{
label1.Text = Convert.ToInt32(textBox1.Text).ToString();
}
}
Thanks