473,508 Members | 2,509 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

textbox text to int error

I can't get a number out of my textbox. it keeps giving me an error and
saying that the input string was not in the correct format.

this.number = int.Parse((this.numberTextBox.Text.ToString());

How do I get the number out of the text box if I only entered small positive
integers?

dave
Nov 15 '05 #1
10 9057
There looks to be too many brackets (parentheseseeses) in your code line
below, that would be my first place to check. Change that to:

this.number = int.Parse( this.numberTextBox.Text.ToString() );

then see if you still have the same problem. It might also be wise to check
that the text box has some text in before you try and convert it to an int.
So the below might be even better still:

if( this.numberTextBox.Text != string.Empty )
{
this.number = int.Parse( this.numberTextBox.Text );
}


"Dave" <da*********@hotmail.com> wrote in message
news:98********************@comcast.com...
I can't get a number out of my textbox. it keeps giving me an error and
saying that the input string was not in the correct format.

this.number = int.Parse((this.numberTextBox.Text.ToString());

How do I get the number out of the text box if I only entered small positive integers?

dave

Nov 15 '05 #2
Generally when I know a certain TextBox will only be able to take Int's I
pass it through a regex function to validate it and then I parse it from
string to int... I alos place a zero as the default text for the TextBox
this way (if you dont use regex) u can make sure that the field will never
be empty (unless changed, thats where regex comes in ;))
"Mark Sizer" <bl**@blah.com> wrote in message
news:Ox**************@TK2MSFTNGP09.phx.gbl...
There looks to be too many brackets (parentheseseeses) in your code line
below, that would be my first place to check. Change that to:

this.number = int.Parse( this.numberTextBox.Text.ToString() );

then see if you still have the same problem. It might also be wise to check that the text box has some text in before you try and convert it to an int. So the below might be even better still:

if( this.numberTextBox.Text != string.Empty )
{
this.number = int.Parse( this.numberTextBox.Text );
}


"Dave" <da*********@hotmail.com> wrote in message
news:98********************@comcast.com...
I can't get a number out of my textbox. it keeps giving me an error and
saying that the input string was not in the correct format.

this.number = int.Parse((this.numberTextBox.Text.ToString());

How do I get the number out of the text box if I only entered small

positive
integers?

dave


Nov 15 '05 #3
nevermind, I figured it out after several days :) It was just that I
disposed the textbox before I got the number out of it. so now I have the
dispose function at the end of that function instead of at the beginning
thanks anyway
dave

"Dave" <da*********@hotmail.com> wrote in message
news:98********************@comcast.com...
I can't get a number out of my textbox. it keeps giving me an error and
saying that the input string was not in the correct format.

this.number = int.Parse((this.numberTextBox.Text.ToString());

How do I get the number out of the text box if I only entered small positive integers?

dave

Nov 15 '05 #4
"Dave" <da*********@hotmail.com> wrote:
I can't get a number out of my textbox. it keeps
giving me an error and saying that the input string
was not in the correct format.


int iValue = 0;

try
{
iValue = Convert.ToInt32(txtValue.Text);
}
catch
{
// Deal with strings that aren't valid integers
}

P.

--
www.CL4.org
Nov 15 '05 #5
Can you give an example regex validation method?

I do not understand regex at all!!

"Mitchell Geere" <mg****@telkomsa.net> wrote in message
news:OB**************@TK2MSFTNGP10.phx.gbl...
Generally when I know a certain TextBox will only be able to take Int's I
pass it through a regex function to validate it and then I parse it from
string to int... I alos place a zero as the default text for the TextBox
this way (if you dont use regex) u can make sure that the field will never
be empty (unless changed, thats where regex comes in ;))
"Mark Sizer" <bl**@blah.com> wrote in message
news:Ox**************@TK2MSFTNGP09.phx.gbl...
There looks to be too many brackets (parentheseseeses) in your code line
below, that would be my first place to check. Change that to:

this.number = int.Parse( this.numberTextBox.Text.ToString() );

then see if you still have the same problem. It might also be wise to

check
that the text box has some text in before you try and convert it to an

int.
So the below might be even better still:

if( this.numberTextBox.Text != string.Empty )
{
this.number = int.Parse( this.numberTextBox.Text );
}


"Dave" <da*********@hotmail.com> wrote in message
news:98********************@comcast.com...
I can't get a number out of my textbox. it keeps giving me an error and saying that the input string was not in the correct format.

this.number = int.Parse((this.numberTextBox.Text.ToString());

How do I get the number out of the text box if I only entered small

positive
integers?

dave



Nov 15 '05 #6
Please can you tell me which function converts integer to
string?You know,if I want to put a integer,lets say x,
variable to textbox1 what do I need to write?


.

Nov 15 '05 #7

"djozy" <an*******@discussions.microsoft.com> wrote in message
news:05****************************@phx.gbl...
Please can you tell me which function converts integer to
string?You know,if I want to put a integer,lets say x,
variable to textbox1 what do I need to write?


.

that's easy. textbox.text = int1.ToString();
just put a dot on the end of the variable and the function ToString() and it
will convert it.
dave
Nov 15 '05 #8
Thank you.I am a begginer.I started with C# few days ago
Nov 15 '05 #9
I know how it is, I just started on it a couple months ago and I found it so
hard that I gave up on doing my project for a little bit. but I'll give you
some advice to help you learn fast.
open up a notepad on the computer and copy and paste little snippets of
code and where they go in there so that you don't ever have to memorize
anything to use it. you will learn very fast this way. look up stuff on the
internet and paste new things there.
also, getting microsoft visual studio will help A TON. trust me. for
example. if you wrote the name of the integer you were talking about and
then put a dot infront of it, it would list the functions that you can use.
and ToString() is one of them. so you would have found that without having
to ask on here. it will help you find lots of stuff you otherwise wouldn't
know how to use or see.
well, good luck
dave
"djozy" <an*******@discussions.microsoft.com> wrote in message
news:03****************************@phx.gbl...
Thank you.I am a begginer.I started with C# few days ago

Nov 15 '05 #10
Here is a link to an article which will explain it to you rather well....

http://www.radsoftware.com.au/web/Co...xAdvanced.aspx
Mitch
"Paul R" <ro********@aol.com> wrote in message
news:eM*************@tk2msftngp13.phx.gbl...
Can you give an example regex validation method?

I do not understand regex at all!!

"Mitchell Geere" <mg****@telkomsa.net> wrote in message
news:OB**************@TK2MSFTNGP10.phx.gbl...
Generally when I know a certain TextBox will only be able to take Int's I
pass it through a regex function to validate it and then I parse it from
string to int... I alos place a zero as the default text for the TextBox
this way (if you dont use regex) u can make sure that the field will never be empty (unless changed, thats where regex comes in ;))
"Mark Sizer" <bl**@blah.com> wrote in message
news:Ox**************@TK2MSFTNGP09.phx.gbl...
There looks to be too many brackets (parentheseseeses) in your code line below, that would be my first place to check. Change that to:

this.number = int.Parse( this.numberTextBox.Text.ToString() );

then see if you still have the same problem. It might also be wise to

check
that the text box has some text in before you try and convert it to an

int.
So the below might be even better still:

if( this.numberTextBox.Text != string.Empty )
{
this.number = int.Parse( this.numberTextBox.Text );
}


"Dave" <da*********@hotmail.com> wrote in message
news:98********************@comcast.com...
> I can't get a number out of my textbox. it keeps giving me an error

and > saying that the input string was not in the correct format.
>
> this.number = int.Parse((this.numberTextBox.Text.ToString());
>
> How do I get the number out of the text box if I only entered small
positive
> integers?
>
> dave
>
>



Nov 15 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
6456
by: Chumley the Walrus | last post by:
I'm using this sql parameter: MyCommand.Parameters("@Sport").value = Server.HtmlEncode(sport) to get a value from a textbox control: <asp:TextBox Name="sport" id="sport"...
2
5501
by: donnet | last post by:
Inside my .aspx file, I have a textbox populated with data from a dataset like this: <asp:TextBox text='<%# DataBinder.Eval(Container.DataItem, "Comment")%>' id="CommentText" runat="server"...
7
2093
by: I am Sam | last post by:
I have a DataGrid that is passing information to a stored procedure properly but the parameters aren't being casted properly. I was woundering if anyone can tell me how I should properly cast the...
11
7712
by: Joe | last post by:
Hello All, I have an ASP.NET page with one Textbox (SearchTextBox) and one ImageButton (SearchButton) server controls. The user can type search text in SearchTextBox and click SearchButton and...
10
9003
by: Jane Sharpe | last post by:
Hi, I have a textbox with the words "Enter your name here" inserted as default text - At the moment, to remove this the user must highlight all the text and delete before they type in their name...
2
12562
by: simon | last post by:
hello, new to vb.net, have a few questions about DataGrid. I have a dataGrid that is working pulling a dataset back from a stored proc and binding to the datagrid for display the datagrid's...
7
9760
by: david | last post by:
I try to use "for" loop to assign textbox control ID to a textbox variable in server side codebehind for a web form. But I met some problem. What I want to do is solving the following-like code by...
0
3482
by: sjickells | last post by:
Hi I am having a problem using asp:TextBox's in a transparent table. I have a background image on the page and a table in the middle of the page. I have set the background colour of the table...
7
2877
by: robert.waters | last post by:
I have an Access database frontend linked via ODBC to a large (gigabytes) mysql database. I need to view a large amount of data in a a textbox (variable up to 300K), but I receive a 'there isnt...
4
8202
by: HenrikL | last post by:
Hi. I have a textbox that have a binding on it with converter and validationrules. When a validation error ouccur the foreground of the textbox will change to red cause it has a style.triggers...
0
7231
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7133
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7405
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7504
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5059
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4724
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3214
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1568
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
435
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.