473,775 Members | 2,570 Online
Bytes | Software Development & Data Engineering Community
+ 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:rangevalida tor 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.repla ce(rex,unescape (s));}

}

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

The page:

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

<asp:RequiredFi eldValidator ID="PopulationR equired" runat="server"
ControlToValida te="txtPopulati on" ErrorMessage="* Population is required."
Display="Dynami c"><img width="25" height="18" border="0"
src="../assets/icons/error.gif" align="absmiddl e"
/></asp:RequiredFie ldValidator>

<asp:RangeValid ator ID="PopulationV alidator" runat="server"
ControlToValida te="txtPopulati on" ErrorMessage="* Population must be numeric
and between 1 and 99999999. " MaximumValue="9 9999999" MinimumValue="1 "
Type="Integer" Display="Static " SetFocusOnError ="True"><img width="25"
height="18" border="0" src="../assets/icons/error.gif" align="absmiddl e"
/></asp:RangeValida tor>


Mar 21 '06 #1
1 3141
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******** ********@TK2MSF TNGP11.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:rangevalida tor 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.repla ce(rex,unescape (s));}

}

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

The page:

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

<asp:RequiredFi eldValidator ID="PopulationR equired" runat="server"
ControlToValida te="txtPopulati on" ErrorMessage="* Population is required."
Display="Dynami c"><img width="25" height="18" border="0"
src="../assets/icons/error.gif" align="absmiddl e"
/></asp:RequiredFie ldValidator>

<asp:RangeValid ator ID="PopulationV alidator" runat="server"
ControlToValida te="txtPopulati on" ErrorMessage="* Population must be
numeric and between 1 and 99999999. " MaximumValue="9 9999999"
MinimumValue="1 " Type="Integer" Display="Static "
SetFocusOnError ="True"><img width="25" height="18" border="0"
src="../assets/icons/error.gif" align="absmiddl e" /></asp:RangeValida tor>



Mar 21 '06 #2

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

Similar topics

0
1502
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 the focus method. The problem is: the focus is lost almost inmediately. I can't type in anything. See the code below.
13
4337
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 structure of the datasets, i.e lots of child tables etc, I cannot use bindingcontext
4
21209
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
2431
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 lost focus event is triggered when the form is shown. I suppose the check code is effective after the form is loaded. Anyone could help? Thanks Best Rdgs Ellis
2
2375
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) NOw. the problem is "When textbox 's Enabled = false. ( the back color still white but not gray) Does anyone know how to solve this problem ?? thanks a lot
8
4079
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 Me.DataType = 2 Then If IsNumeric(Me.Text) Then Me.TextAlign = HorizontalAlignment.Right End If
0
2303
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 some Textboxes with total values. However, on the OnTextChanged Event the focus is lost i.e. when my user
3
11513
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 javascript to change the backgorund color when it has focus but how can I change the background color again when it lost the focus my code is as below
5
13524
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 1111.1 it will immediately be converted to 1,111.10 as its value. I've tried using this code in every lost focus: textbox.text = round(val(textbox.text)), 2) but the problem with this is I am not getting the comma and if the user enters an exact...
0
9454
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,...
0
10268
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, 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...
0
9916
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7464
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6718
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();...
0
5360
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...
0
5486
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3611
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2853
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 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...

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.