Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > IsNumeric Function

Reply
Thread Tools

IsNumeric Function

 
 
=?Utf-8?B?TXJNaWtl?=
Guest
Posts: n/a
 
      11-29-2004
Hi. I'm trying to create a simple validation process that only allows a user
to enter a numeric value into a textbox. However, my process does not work
and the user can still enter non-numeric values. My code is below. How can
I fix this? Thanks.

If Not (IsNumeric(CType(e.Item.Cells(3).Controls(0), TextBox).Text)) Then
Me.lblErrorMsg.Text = "Only numeric values allowed!"
Exit Sub
End If
 
Reply With Quote
 
 
 
 
Dan Bass
Guest
Posts: n/a
 
      11-29-2004
Mike,

A suggestion would be to scrap this code behind and go with client side
validation. What you're doing isn't wrong, but it does mean a post-back has
to a occur before the user will see their error. It's better to have a
CompareValidator that contains your text error string, where the operator =
"DataTypeCheck" and the Type is "Integer"...

This will only allow a postback if the value in the textbox is an integer.

Google on CompareValidator for more, or let me know if you need more help.

Daniel.


"MrMike" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi. I'm trying to create a simple validation process that only allows a
> user
> to enter a numeric value into a textbox. However, my process does not
> work
> and the user can still enter non-numeric values. My code is below. How
> can
> I fix this? Thanks.
>
> If Not (IsNumeric(CType(e.Item.Cells(3).Controls(0), TextBox).Text)) Then
> Me.lblErrorMsg.Text = "Only numeric values allowed!"
> Exit Sub
> End If



 
Reply With Quote
 
 
 
 
Hans Kesting
Guest
Posts: n/a
 
      11-29-2004
MrMike wrote:
> Hi. I'm trying to create a simple validation process that only
> allows a user to enter a numeric value into a textbox. However, my
> process does not work and the user can still enter non-numeric
> values. My code is below. How can I fix this? Thanks.
>
> If Not (IsNumeric(CType(e.Item.Cells(3).Controls(0), TextBox).Text))
> Then Me.lblErrorMsg.Text = "Only numeric values allowed!"
> Exit Sub
> End If


Use a "CompareValidator", with type set to integer and operator
set to datatypecheck. Don't forget the "ControlToValidate"


Hans Kesting


 
Reply With Quote
 
=?Utf-8?B?VGFtcGEgLk5FVCBLb2Rlcg==?=
Guest
Posts: n/a
 
      11-29-2004
Mike,
Remember, even though you wrote this code:
Me.lblErrorMsg.Text = "Only numeric values allowed!"

You still don't through an exception, therefore this will still cause the
form to post its values. Like the others explained, use the asp.net
validation controls to stop users from entering bad values

"MrMike" wrote:

> Hi. I'm trying to create a simple validation process that only allows a user
> to enter a numeric value into a textbox. However, my process does not work
> and the user can still enter non-numeric values. My code is below. How can
> I fix this? Thanks.
>
> If Not (IsNumeric(CType(e.Item.Cells(3).Controls(0), TextBox).Text)) Then
> Me.lblErrorMsg.Text = "Only numeric values allowed!"
> Exit Sub
> End If

 
Reply With Quote
 
=?Utf-8?B?TXJNaWtl?=
Guest
Posts: n/a
 
      11-29-2004
Thank you all for your posts. I've successfully implemented a
comparevalidator as suggested. I'm still making the transition from Access
VBA to VB.NET

Thanks!

"Tampa .NET Koder" wrote:

> Mike,
> Remember, even though you wrote this code:
> Me.lblErrorMsg.Text = "Only numeric values allowed!"
>
> You still don't through an exception, therefore this will still cause the
> form to post its values. Like the others explained, use the asp.net
> validation controls to stop users from entering bad values
>
> "MrMike" wrote:
>
> > Hi. I'm trying to create a simple validation process that only allows a user
> > to enter a numeric value into a textbox. However, my process does not work
> > and the user can still enter non-numeric values. My code is below. How can
> > I fix this? Thanks.
> >
> > If Not (IsNumeric(CType(e.Item.Cells(3).Controls(0), TextBox).Text)) Then
> > Me.lblErrorMsg.Text = "Only numeric values allowed!"
> > Exit Sub
> > End If

 
Reply With Quote
 
Dan Bass
Guest
Posts: n/a
 
      11-29-2004

> Thank you all for your posts. I've successfully implemented a
> comparevalidator as suggested. I'm still making the transition from
> Access
> VBA to VB.NET


Good to ask questions, even better to listen to the answers. Looking at the
guys around these parts, I realise I know's nothing!


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
IsNumeric C# equivalent Stephan Bour ASP .Net 12 01-26-2012 12:48 PM
New String.isNumeric() function in Java 1.6 ? Ulf Meinhardt Java 0 08-11-2009 08:41 AM
I have a isNumeric function to check a text field is numeric .. I nowneed a isFloat bizt Javascript 13 09-18-2008 10:51 PM
.NET IsNumeric function =?Utf-8?B?Sm9l?= ASP .Net 7 02-08-2006 12:08 AM
Isnumeric and importing vb functions martin ASP .Net 3 07-19-2004 11:41 AM



Advertisments