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.

 All Forums
 Development Tools
 ASP.NET
 New to ASP.NET

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 using

Int32.TryParse()

Dean Fiala
Very Practical Software, Inc
Now with Blogging...
http://www.vpsw.com/blogbaby
Microsoft MVP
Go to Top of Page

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 error

CS0117: 'int' does not contain a definition for 'TryParse'

Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2006-05-22 : 13:57:21
make sure you read about TryParse() before using it.

http://msdn2.microsoft.com/en-us/library/f02979c7.aspx

On-line help is your friend.
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2006-05-22 : 13:57:48
two things:

1) make sure you read about TryParse() before using it.

http://msdn2.microsoft.com/en-us/library/f02979c7.aspx

and

2) It is only available in .NET 2.0.
Go to Top of Page
   

- Advertisement -