Displaying an alert when a validator fails

Hi All,

I've got a RangeValidator that ensures that the integer input in a textbox is in the allowed range.  It pops up some red error text next to the textbox if they enter the wrong text.

I am wondering if there is a way to trigger a dialog box (e.g., alert('You must enter a value between 5 and 15')) if they enter an invalid number in the field.  The reason being, we've had a number of people who go through past that field quickly, and don't notice the red error text.  The alert() dialog, which will interrupt user activity and give an audion alert, will (hopefully) cut down on some of the errors.

I only want it to trigger when  they've entered invalid text.  So, I need to register a custom script block (really, just a one line "alert()" statement) if the client side validation is fired and fails.

How do I do that?  I know there must be a way...

  -Josh





 


-jb
0
jbeall
9/26/2006 8:42:00 PM
asp.net.web-forms 93655 articles. 6 followers. Follow

8 Replies
670 Views

Similar Articles

[PageSpeed] 57
Get it on Google Play
Get it on Apple App Store

you can use the validation summary's "ShowMessageBox" attribute, like this:  

<asp:ValidationSummary ID="vs" ShowMessageBox="true" />



RateMyEverything
0
PhaedoHD
9/26/2006 11:13:12 PM

But I want it to show them the alert as soon as they move off the text box (if they've entered an invalid date).  This won't work until they hit the submit button, I believe...


-jb
0
jbeall
9/27/2006 12:32:20 PM

hi Jbeall,

you can do this by using Java script..

in Page_Load

txt1.Attributes.Add("onblur", "checktext();");

In HTML page script block

function checktext()

{

var Tbox1 = document.getElementById( 'txt1' );

if( Tbox1.value >15)   // change according to your reqs

{

alert('please enter ............... in range');

return false;

}

}



My Blog


"Don't be afraid to be wrong; otherwise you'll never be right."
0
budugu
9/27/2006 3:13:23 PM

Yes, this is in fact what I'm doing right now.

I was just hoping there was some way to make the JS fire only when my validator failed.  Conceptually, here's what I wanted to do:

 
<asp:TextBox runat='server' ID='LengthInFeet'/>
<asp:RangeValidator runat='server' ID='LengthRangeValidator' MinimumValue='2' MaximumValue='10' Type='Integer' OnClientValidationFailure='alert("Valid lengths are 2 through 10");' />

 
The last bit that I put in bold is made up -- you can't really do that.

But it's what I was hoping to do.  If I could do that, then all my validation logic would be right there in my <asp:RangeValidator>  tag.  As it is now, I've got logic in both the .aspx and the .aspx.cs file.


But perhaps that's just the way it has to be. 


-jb
0
jbeall
9/27/2006 4:14:15 PM

Try this..  this function alert the user if he/she enters text length less than 2 charcters or more than 10 characters otherwise the function do nothing..

basically it is just a client side validation when the focus moves away from that textbox

function validate()

{

 

var txt1 = document.getElementById("txt1");

if(txt1.value.length < 10 || txt1.value.length >2 )  // checking the length of the string

return true;

else

{

alert("Please Enter a Valid Number?");

return false;

}

 

}



My Blog


"Don't be afraid to be wrong; otherwise you'll never be right."
0
budugu
9/27/2006 5:38:33 PM

Hi jb,

I am the author of a commercial validation solution, Professional Validation And More. I built my software because there are numerous limitations to the original validators that demand hacks, extra coding, or simply cannot be done. This is a classic case. Another which would get the users attention is to change the color of the textbox when there is an error. A third, which is supported in ASP.NET 2, is to set focus back to the field with the error. (Use the SetFocusOnError property.) A fourth is to blink the error message a few times. All of these are reasonable solutions, yet you have to work within the constraints of the tool you have selected.

I can see a hack being brewed in this thread. I've never considered a hack for this before, but I would imagine it involving these elements:

1. Attach code to the onchange event to be run after all validators do their work.

2. Look through the list of validators assigned to that textbox and see if their isValid property is false.

3. Create a string containing the error messages from those validators and call alert() with it.

If you use my solution, its a built in feature (just like most the things users have demanded of validation). Just set the PeterBlum.VAM.Globals.Page.ShowAlertOnChange property to true in Page_Load. (My code supports all of the ways to get the user's attention described above.)


--- Peter Blum
Creator of Peter's Data Entry Suite (formerly Professional Validation And More and Peter's Date Package) and Peter's Polling Package
www.PeterBlum.com
0
PLBlum
9/27/2006 6:11:23 PM

Hi Peter,

Thanks for the feedback.  I'll definitely be keeping your control set in mind.  I've seen it before and they look pretty powerful.

This is a different topic, but since I seem to have managed to attract the attention of someone who really knows how controls work, and how to build custom controls, I was wondering if you can give any insight into this.  How do I get Visual Studio to recognize that I can have child elements of a custom control?  I have made a control called EnhancedDropDownList, and it has ListItems as children.  It compiles fine, pages load and run fine, but Visual Studio gives me an error for every <asp:ListItem> that I have as a child.  How do I get that error to go away?  The thread discussing it is here -- nobody seems to know how to fix it.  I thought you might?

  -Josh
 


-jb
0
jbeall
9/28/2006 3:56:34 PM
OK, I've given an answer there.
--- Peter Blum
Creator of Peter's Data Entry Suite (formerly Professional Validation And More and Peter's Date Package) and Peter's Polling Package
www.PeterBlum.com
0
PLBlum
9/28/2006 6:37:41 PM
Reply:

Similar Artilces:

C#.NET WEB APPLICATION
hei guys, i need help on my application, i'm using C#.NET as front-ed and SQL as back-end, aside from a datagrid, i want to display my data using textboxes and not a datagrid, i can do it using Visual Basic 6 but since i'm a newbee at C#.NET i don't know how to do it, specially the codes, can anyone help me with it? thank you in advance! If you are doing windows development, i would suggest using 'DataForm wizard' (Use Solution Explorer-->Rightclick project-->Add new Item-->New DataForm). It will guide you through steps. If you are doing web apps. Use quickstart to learn them. h...

Strange output in web form after web form is displayed.
   I have been using a web user control for over a week now with no problems. I am now getting strange output in my web form after my controls display on the page. Below is the strange output. Can anyone tell me what is wrong here? Note I did not include it all because it is quite large.   Request Details Session Id: l5b5vkazucfatba4oliaw1vi Request Type: POST Time of Request: 9/10/2007 4:59:59 PM Status Code: 200 Request Encoding: Unicode (UTF-8) Response Encoding: Unicode (UTF-8) Trace Information Category Message From First(s) F...

Return to web form after validation failed
Hi All, I am not sure how to do this.  Here I go...  I got a form for data entry and validation controls for all the required fields.  When a user click on the submit button (passed the web form validation), there is another validation that I am checking for double entries.  If the data is duplicate or exist already in the database, I want to prevent the user from saving the data and return with a error message.  How would I do that?  TIA  Steve I would think that an If..Then..Else statement would do the trick for you.  Run your SQL query to see i...

Implementing .Net Form into an APS.net web form, can this be done
I am new here, but have been searching for a while, and may not have the correct lingo to find what I am looking for.  I am tasked with implementing a .exe application that was writen vb6 then converted to .net into a new website my team is developing. The idea is to put each of the 3 different forms in this .exe application of 3 different .aspx pages. I have attempted multiple things to get this into the page and even started to just rewrite it as an ASP.net web form, but even then I can't reuse any of the code since the System.Web.UI.Page doesn't inherit the sa...

DataWindow Failed to Retrieve in .NET Web Form
I am running PB 11.5.1 Build 4788. I have a datawindow that would retrieve normally under client server mode, but do not retrieve under .NET Web Forms (returns nothings). I am running the same source code in both modes. The retrieval arguments of the said DataWindow are (Date, Time, Integer). The code is as follow: This.DataObject = 'dw_actsch_sch' This.SetTransObject( sqlca ) li_RtnVal = This.Retrieve( Date( '2010-09-10' ), Time( '10:00.00' ), 1 ) The li_RtnVal is -1 when it is running in web form. I am wondering if anyone has similar experiences,...

Using excel/automation from a .net web form fails, why?
Hi all - From my codebehind I'm attempting to write the contents of a DataSet to Excel. However, it appears that I cannot start Excel from my codebehind to accomplish this. Doing so causes the following error: Cannot execute a program. The command being executed was "c:\winnt\microsoft.net\framework\v1.1.4322\csc.exe" /noconfig @"C:\WINNT\Microsoft.NET\Framework\v1.1.4322\Temporary ASP.NET Files\webservice_icspos_consumer\bd8c4cb9\af1c8054\s33rwgwf.cmdline". I've referenced Microsoft Excel 10.0 Object Library which also brings in - Microsoft Office 10.0 Obje...

Web Form Fails To Load in VS.NET w/ sample code
I have a BasePage class and a StandardPage class. The BasePage inherits from the System.Web.UI.Page object, and then the StandardPage inherits from BasePage. System.Web.UI.Page | | BasePage | | StandardPage The BasePage has some Properties that access the Request object. Now I have an 'index.aspx' page with no codebehind and inherits the 'StandardPage' object through the PageDirective tags. When I try to view the 'index.aspx' in the designer, it breaks saying "accessor fails... Request has no instance' (Something like that) Anyway when I comment o...

.NET 1.1 Web Form
I am scratching my head trying to figure out why my events button (Lighting Bolt) is not displaying when I select buttons in Visual Studio 2003.  Has anybody had this happen before? I am tired into Visual Source Safe and wonder if that has anything to do with it?Moojjoo Õ¿Õ http://www.mmwebs.comhttp://moojjoo.blogspot.com/ Ummm>>>   That is the difference between C# and VB.NET.  VB.NET does not display the Lightning Bolt under properties in VS 2003.Moojjoo Õ¿Õ http://www.mmwebs.comhttp://moojjoo.blogspot.com/...

windows forms in vb .net into web forms
we are creating a database driven website as part of our project. currently we have forms connecting to the database created in visual basic. these windows forms we need to convert into web forms which are asp .net compatible. can u give me an answer or show me a way. Hi, because of the difference in nature between web and win applications you'll need to reimplement at least the UI part. If you have a multitiered application in which the busines logic and data access are in different parts/assemblies you can reuse them. Grz, Kris.Read my blog. Handy Firefox plugins for web developers.Wor...

validate Textbox in Web User Control from web form?
ASP.NET 2.0 I have a web user control that contains a textbox.  I need to add some validation (like requiredfieldvalidator, comparevalidator, etc). I would normally add the validator to my web user control by placing the validator next to my textbox.  However, I need the validation message somewhere else on my web form, not near the user control. So how would I associate a validation control on my web form with the text box inside my web user control?  Can this be done; any alternatives out there? Thanks!   The error message should occur wherever you place the vali...

.Net Web Form & Web Service Deployment
Hi all I have written some test web services and some web form applications and deployed them to my IIS. That's fine but I now want to deploy them to my real IIS server. I have created an msi for each but the problem is I seem to only be able to deploy to the default web site. Our default web site is turned off and instead we use several other sites. Does anybody happen to if Powerbuilder 11 supports non default web sites? If not do I need to hack the msi and if so can anybody suggest a suitable tool. I have Orca but it's not very friendly. Unless of course I knew exactly w...

How to Make Web Forms from other Web Forms
In putting together an ASP.NET application for a biz application, we have come to the point where there are three different types of basic forms which have, for the most part, been perfected. Now its is a matter of cloning those forms for various uses and modifying or adding code to suit the particular need. Copy and paste works OK, but there is a lot of changing of certain words, etc. Is there a way in ASP.NET to take these basic forms, turn them into classes or templates, create forms from them, then add or overwrite code? ? (Anybody who is a Vis Fox Pro programmer would know imme...

Web forms and mobile web forms
Hey everyone, I am looking to develope a web site that depending on the device connecting to it, it will display a certain page. In this case im looking to create a web and wap version of the same project. I have the Web forms version finished using ASP.NET and C# and I am wondering how to create the mobile web form and incorporate it in the project. In the project folder, can I just add a mobile web??? But what about displaying device specific pages?? Cheers -Dudach Yes, you can add mobile web forms and controls to your Web Application project. No problem. For device/br...

Sharepoint help! Error msg : "A Web Part or Web Form Control on this Web Part Page cannot be displayed or imported because it is not registered on this site as safe"
hihi, I have set up a testing virtual server on my local machine. I installed win server 2003, wss 2.0, sql server 2000, and visual studio .net 2003. i tried to create a project in C# but when i build it and import the web part (.dwp) into the page, there is this error msg "A Web Part or Web Form Control on this Web Part Page cannot be displayed or imported because it is not registered on this site as safe"  I seached most of the sites and they informed that the problem lies in the safe control in web.config i enter the safe control in web.config but i does not know where to put ...

Web resources about - Displaying an alert when a validator fails - asp.net.web-forms

List of mammals displaying homosexual behavior - Wikipedia, the free encyclopedia
For these mammals, there is documented evidence of homosexual behavior of one or more of the following kinds: sexual behavior , courtship , affection ...

Facebook Displaying Page Insights On Page Admins’ Personal Pages?
Some Facebook page administrators are seeing modules on their personal pages displaying page insights ad, campaign , and like totals for pages ...

Facebook Displaying Unread Messages from Pages in a New Updates Module
Facebook is displaying a new “Updates” sidebar module which shows some users unread messages sent to them by Pages. Users will see the Updates ...

Don Lemon Holds Up Sign Displaying the N-Word, Uncensored, on Air CNN Live - YouTube
Don Lemon Holds Up Sign Displaying the N-Word, Uncensored, on Air Lemon held up a Confederate flag first before holding up the sign. He asked, ...

Hazelwood coal mine fire: Morwell residents displaying symptoms similar to cigarette smokers, expert ...
An expert says some locals near Victoria's Hazelwood mine fire have symptoms similar to cigarette smokers.

Police accused of displaying fake G20 weapons
Toronto's top police officer misled the public by displaying fake weapons used in a medieval-themed role-playing game to help justify their actions ...

No charges for U.S. host for displaying high-capacity magazine on TV
NBC television journalist David Gregory won't face charges for displaying a high-capacity ammunition magazine on his "Meet the Press" news program ...

Jays' Escobar suspended three games for displaying slur
Toronto Blue Jays shortstop Yunel Escobar has been suspended three games for displaying a homophobic slur on his eye-black during a game on Saturday. ...

Google Play Store now displaying age-based ratings
We reported back in May that Google was adding age-based ratings to all apps in the Play Store as determined by the International Age Rating ...

Apple displaying Ferraris & other cars at WWDC hinting at CarPlay announcements
... 2014 Filed under: AAPL Company , iOS Continue reading more about AAPL Company and iOS at 9to5Mac . What do you think? Discuss "Apple displaying ...

Resources last updated: 1/6/2016 8:55:12 AM