Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
svicky9
Posting Yak Master
232 Posts |
Posted - 2006-05-18 : 13:56:09
|
Line 3: void Page_Load()Line 4: { Line 5: int a = Convert.ToInt32(txtnum.Text);Line 6: square(a);Line 7: lblnumber.Text = a.ToString();System.FormatException: Input string was not in a correct format.what is the error there???Vic |
|
dfiala
Posting Yak Master
116 Posts |
Posted - 2006-05-18 : 13:59:34
|
If txtnum.Text is blank or has non numeric charcters, the format exception will be thrown.If you're not sure of your input, you'd be better off usingInt32.TryParse()Dean FialaVery Practical Software, IncNow with Blogging...http://www.vpsw.com/blogbabyMicrosoft MVP |
 |
|
svicky9
Posting Yak Master
232 Posts |
Posted - 2006-05-22 : 12:37:50
|
I tried the following code<%@page language ="C#" debug ="true" %><script runat = "server" language ="C#">void Page_Load(){ int a; a = Int32.TryParse(txtnum.Text); square(a); lblnumber.Text = a.ToString(); } void square(int i) { i = i * i; } </script><html><body><form runat ="server">Passing a parameter as value.<br /><asp:TextBox ID ="txtnum" Runat ="server"></asp:TextBox><asp:Label ID ="lblnumber" Runat ="server"></asp:Label><input type = "submit" runat ="server"></form></body></html>It gives me this errorCS0117: 'int' does not contain a definition for 'TryParse' |
 |
|
jsmith8858
Dr. Cross Join
7423 Posts |
|
jsmith8858
Dr. Cross Join
7423 Posts |
|
|
|
|