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(CTyp e(e.Item.Cells( 3).Controls(0), TextBox).Text)) Then
Me.lblErrorMsg. Text = "Only numeric values allowed!"
Exit Sub
End If 5 4680
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
CompareValidato r that contains your text error string, where the operator =
"DataTypeCh eck" and the Type is "Integer".. .
This will only allow a postback if the value in the textbox is an integer.
Google on CompareValidato r for more, or let me know if you need more help.
Daniel.
"MrMike" <Mr****@discuss ions.microsoft. com> wrote in message
news:3C******** *************** ***********@mic rosoft.com... 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(CTyp e(e.Item.Cells( 3).Controls(0), TextBox).Text)) Then Me.lblErrorMsg. Text = "Only numeric values allowed!" Exit Sub End If
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(CTyp e(e.Item.Cells( 3).Controls(0), TextBox).Text)) Then Me.lblErrorMsg. Text = "Only numeric values allowed!" Exit Sub End If
Use a "CompareValidat or", with type set to integer and operator
set to datatypecheck. Don't forget the "ControlToValid ate" :-)
Hans Kesting
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(CTyp e(e.Item.Cells( 3).Controls(0), TextBox).Text)) Then Me.lblErrorMsg. Text = "Only numeric values allowed!" Exit Sub End If
Thank you all for your posts. I've successfully implemented a
comparevalidato r 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(CTyp e(e.Item.Cells( 3).Controls(0), TextBox).Text)) Then Me.lblErrorMsg. Text = "Only numeric values allowed!" Exit Sub End If Thank you all for your posts. I've successfully implemented a comparevalidato r 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! This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: eje |
last post by:
IsNumeric(value) should return false if value "can not be
successfully converted to a Double." Instead I get the
following error message: "Input string was not in a
correct format."
I use the following function in a validating class to use
when needed. (Value = H880118A gave the error (like
other 'unconvertible' strings))
Public Function Numeric(ByVal value) As Boolean
|
by: Eugene Anthony |
last post by:
I have received the following feedback for the two functions bellow:
"The ISNUMERIC test is WORTHLESS for checking for an INT value, because
ISNUMERIC will happily accept DOUBLE values, such as 89.11998811777 and
other values that are simply *NOT* INT values."
<%
function isZip(input)
|
by: Kenny |
last post by:
Hello,
I would like to know if the function IsNumeric requires a header like
#include <iostream> to be functionnal
thanks
ken
|
by: John Bowman |
last post by:
Hello,
Does anyone have a good/reliable approach to implementing an IsNumeric()
method that accepts a string that may represent a numerical value (eg. such
as some text retrieved from an XML file)? Thus if you pass it "1" or
"5.12345" it returns true, but "1b3q" it returns false? I know VB has this
sort of function, but was wondering how to implement something similar in
C#. I suppose I could use the Convert methods and catch any...
|
by: michele |
last post by:
I have a problem with VB.Net and IsNumeric() function because it always
returns FALSE even the string can be a number.
There is another strange thing, the same program (it is a test) runs good on
one and doesn't run an another one.
The program test is very simple, just a form with a text box and a button.
The text box has a validation rule that check if the insert string is a
numeric value, that's all.
| |
by: Dave |
last post by:
I'm trying to import Microsoft.VisualBasic to use the IsNumeric function in
my C# code but all I see is:
Microsoft.VisualBasic.VBCodeProvider while using Intellisense...
From samples shouldn't I see Microsoft.VisualBasic.Information.IsNumeric?
Thanks
|
by: Nathan Truhan |
last post by:
All,
I think I may have uncovered a bug in the IsNumeric function, or at least a
misunderstanding on functionality.
I am writing a Schedule Of Classes Application for our campus and have a
section that lists the Times, Buildings and rooms for courses.
In this section I have a function called PadCell that takes3 parameters, one
the value, one a padd count and one a a boolean input called StripNumeric,
that if true, checks if the value...
|
by: Kimelia Schiles |
last post by:
Hi,
I am new to C#, and I am a VB programmer. I would like to know whether there
is any function in C# that can is similar to IsNumeric in VB?
|
by: sck10 |
last post by:
Hello,
I am trying to determine if a value is NOT numeric in C#. How do you test
for "Not IsNumeric"?
protected void fvFunding_ItemInserting_Validate(object sender,
FormViewInsertEventArgs e)
if (e.NewValues != "" && Not IsNumeric(e.NewValues))
{
|
by: =?Utf-8?B?VG9ueQ==?= |
last post by:
Can anybody tell why IsNumeric("5-") is true?
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |