473,466 Members | 1,360 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

revalidate on textbox's lost focus??

I have a asp:textbox which I've applied a javascript function to strip off
all non-numeric chanarcters. The js function is triggered with the textbox's
onblur attribute. I also have a rangevalidator to make sure the value
entered is numeric and is between 1 & 999999.

The custom js works fine. If someone enters 7,777 or even something invalid
like 7,7,7,7, all the commas are stripped off as soon as they tab off the
field and all that is left is 7777. The problem is that ANY data entry
containing anything other than the acceptable range WITH commas, it still
triggers the asp:rangevalidator error.

So if they enter 7,000, the comma is stripped off BUT the rangevalidator is
still triggered when the field is tabbed off. How can I prevent this? Or
should I ask - how can I get the rangevalidator to test upon the lost focus
of the field. It sort of does this anyway because when I make a
"correction" and type 7000 again (typing exactly what is there) and tab off,
the rangevalidator goes away.

Thoughts? What would you do?

The custom js:
function tmt_reFormat(f,re,s){

fv=MM_findObj(f).value;var rex=new RegExp(unescape(re),"g");

if(rex.test(fv)){MM_findObj(f).value=fv.replace(re x,unescape(s));}

}

On page_load:
txtPopulation.Attributes.Add("onblur",
"tmt_reFormat('txtPopulation','%5B%5E%5Cd%5D','')" )

The page:

<asp:TextBox ID="txtPopulation" runat="server">0</asp:TextBox>

<asp:RequiredFieldValidator ID="PopulationRequired" runat="server"
ControlToValidate="txtPopulation" ErrorMessage="*Population is required."
Display="Dynamic"><img width="25" height="18" border="0"
src="../assets/icons/error.gif" align="absmiddle"
/></asp:RequiredFieldValidator>

<asp:RangeValidator ID="PopulationValidator" runat="server"
ControlToValidate="txtPopulation" ErrorMessage="*Population must be numeric
and between 1 and 99999999. " MaximumValue="99999999" MinimumValue="1"
Type="Integer" Display="Static" SetFocusOnError="True"><img width="25"
height="18" border="0" src="../assets/icons/error.gif" align="absmiddle"
/></asp:RangeValidator>


Mar 21 '06 #1
1 3101
Shane,

Change your custom JS to fire "OnKeyDown".

That way any commas, etc. will be removed immediately and you won't run into
the conflict of the built in validator firing first when tabbing off the
control.

Regards,

--
S. Justin Gengo
Web Developer / Programmer

Free code library:
http://www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"D. Shane Fowlkes" <sh**********@h-o-t-m-a-i-l.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
I have a asp:textbox which I've applied a javascript function to strip off
all non-numeric chanarcters. The js function is triggered with the
textbox's onblur attribute. I also have a rangevalidator to make sure the
value entered is numeric and is between 1 & 999999.

The custom js works fine. If someone enters 7,777 or even something
invalid like 7,7,7,7, all the commas are stripped off as soon as they tab
off the field and all that is left is 7777. The problem is that ANY data
entry containing anything other than the acceptable range WITH commas, it
still triggers the asp:rangevalidator error.

So if they enter 7,000, the comma is stripped off BUT the rangevalidator
is still triggered when the field is tabbed off. How can I prevent this?
Or should I ask - how can I get the rangevalidator to test upon the lost
focus of the field. It sort of does this anyway because when I make a
"correction" and type 7000 again (typing exactly what is there) and tab
off, the rangevalidator goes away.

Thoughts? What would you do?

The custom js:
function tmt_reFormat(f,re,s){

fv=MM_findObj(f).value;var rex=new RegExp(unescape(re),"g");

if(rex.test(fv)){MM_findObj(f).value=fv.replace(re x,unescape(s));}

}

On page_load:
txtPopulation.Attributes.Add("onblur",
"tmt_reFormat('txtPopulation','%5B%5E%5Cd%5D','')" )

The page:

<asp:TextBox ID="txtPopulation" runat="server">0</asp:TextBox>

<asp:RequiredFieldValidator ID="PopulationRequired" runat="server"
ControlToValidate="txtPopulation" ErrorMessage="*Population is required."
Display="Dynamic"><img width="25" height="18" border="0"
src="../assets/icons/error.gif" align="absmiddle"
/></asp:RequiredFieldValidator>

<asp:RangeValidator ID="PopulationValidator" runat="server"
ControlToValidate="txtPopulation" ErrorMessage="*Population must be
numeric and between 1 and 99999999. " MaximumValue="99999999"
MinimumValue="1" Type="Integer" Display="Static"
SetFocusOnError="True"><img width="25" height="18" border="0"
src="../assets/icons/error.gif" align="absmiddle" /></asp:RangeValidator>



Mar 21 '06 #2

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

Similar topics

0
by: Carlos Lozano | last post by:
Hello everybody, I Have a piece of code for a Pocket PC that has a disabled and hidden textbox control at startup. It is enabled and set visible programatically. The cursor is captured calling...
13
by: Paul Slavin | last post by:
I have a textbox bound to a dataview, when I update the text in the textbox no changes take place in the underlying dataset. Why is this?? any answers appreciated, as to due to the underlying...
4
by: Bernard Bourée | last post by:
I have some TextBoxes created by code. I want to write a procedure to handle the lost of focus of any of these TextBox. How should I do that ? Thanks --
6
by: Ellis Yu | last post by:
Hi all, I've a form containing some textbox fields. I wrote a simple code to check if the field is blank in lost focus event, an msg box will be shown to remind user about it. But don't why the...
2
by: Agnes | last post by:
When the textbox 's Enabled = True, (its backcolor is white) When the Textbox got focus (backcolor change to pink by my code) when the textbox lost focus(back color change to white by my code)...
8
by: Martin | last post by:
Hi all, I'm trying to make a subclass of the Textbox. One of the things I did there is the following: Protected Overrides Sub OnLeave(ByVal e As System.EventArgs) If Me.DataType = 1 Or...
0
by: =?Utf-8?B?Qw==?= | last post by:
Hi, I have a series of textboxes on an aspx page. These textboxes are within an UpdatePanel. On the OnTextChanged Event of each textbox I do some calculations in my codebehind and update...
3
by: viral123 | last post by:
Hi all, does any one know how to get the functionality of get focus and lost focus using ASP.Net like VB.Net I want to change the textbox back ground color when it has the focus. I used...
5
montzter
by: montzter | last post by:
Hi evryone, I'm having trouble in formatting the inputed data in the text box so that everytime user lost focus it will adjust its value to contain the format (#,####.##). ie user will input...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
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,...
0
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...
1
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...
0
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...
0
agi2029
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,...
0
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
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
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 ...

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.