When using TextBox2.Text
as a source for a numeric value, you must first check if the value exists, and then convert to an integer.
If the text box is empty when called Convert.ToInt32
, you will receive System.FormatException
. Suggest a try:
protected void SetImageWidth()
{
try{
Image1.Width = Convert.ToInt32(TextBox1.Text);
}
catch(System.FormatException)
{
Image1.Width = 100; // or other default value as appropriate in context.
}
}
source
share