protected void setImageWidth() int imageWidth; if (Label1.Text != null) imageWidth = 1 * Convert.ToInt32(Label1.Text); Image1.Width = imageWidth; After to run the page on a browser, I acquire the System.FormatException: intake string was no in a exactly format.

You are watching: Input string was not in a correct format



The trouble is v line

imageWidth = 1 * Convert.ToInt32(Label1.Text);Label1.Text might or might not be int. Check.

Use Int32.TryParse(value, out number) instead. That will fix your problem.

See more: Buy Diablo 3 Wings Of The Betrayer Diablo 3, Wings Of The Betrayer

int imageWidth;if(Int32.TryParse(Label1.Text, out imageWidth)) Image1.Width= imageWidth;



If making use of TextBox2.Text as the resource for a numeric value, that must very first be checked to check out if a worth exists, and also then converted to integer.

If the text box is empty when Convert.ToInt32 is called, girlfriend will get the System.FormatException. Suggest trying:

protected void SetImageWidth() try Image1.Width = Convert.ToInt32(TextBox1.Text); catch(System.FormatException) Image1.Width = 100; // or other default worth as ideal in context.


Because Label1.Text is holding label which can"t be parsed right into integer, you need to transform the associated textbox"s text to integer

imageWidth = 1 * Convert.ToInt32(TextBox2.Text);
Highly active question. Knife 10 reputation (not counting the combination bonus) in order to answer this question. The reputation requirement helps protect this concern from spam and also non-answer activity.

Not the price you're looking for? Browse other questions tagged c# or questioning your own question.

Unity 2017.2.0f3 v Facebook 7.10.1 build error FormatException: input string was no in the correct format
site architecture / logo © 2021 stack Exchange Inc; user contributions license is granted under cc by-sa. Rev2021.11.5.40661

your privacy

By click “Accept all cookies”, girlfriend agree ridge Exchange can store cookies on your device and disclose info in accordance with our Cookie Policy.