HEXAQ : A friendly question - answer site for IT professionals

ASP.NET - Input string was not in a correct format


0

I am facing error when trying to assign value of text box to int variable.

Below is my code

int a;
a = Convert.ToInt32(Textbox1.Text);

it works randomly and throws error frequently.

Â
asked
 


≡ Total 1 Answer

0

You are converting any value entered in the textbox. Sometimes if the value entered in textbox is not a number, your code will throw error.

You can add a RegularExpression Validator to ensure entered value is numeric only.

Validator will do the job.

Â
replied


Enter your reply here
Answer Preview: