473,548 Members | 2,598 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how do I make the validator cut off other code on the page from executing?

At
http://www.brainjammer.com/testing/validator_test.aspx
I have a text field where you can enter text, and a button where if you
click the button, it sets the value of a label below it, to display the
text you entered in a text field. There is also a
RequiredFieldVa lidator for the text field so that you get an error if
you leave it blank.

As long as I have EnableClientScr ipt set to true for the
RequiredFieldVa lidator, if I leave the text field blank and click the
button (ignore what the button caption says, "hide this panel" etc.),
the RequiredFieldVa lidator shows, and the text of the label below it
does not get set to blank. i.e., when the validator detects an error
in the field, it stops the other button click handling code from
running, which is what you'd expect.

The problem is that if EnableClientScr ipt for the validator is set to
false (which is how I have it set now), then when you enter blank for
the text field and click the button, the validator still displays,
*but* the text of the label below it also changes to blank. So when
the validator is set to only do server-side validation, it doesn't cut
off the other button click handling code from executing when it detects
an error.

Is there any way to make the validator stop the button's onclick event
code from running if the validator detects an error in the field that's
submitted?

I can just set EnableClientScr ipt to true, but some of our users have
JavaScript turned off in their browser, which appears to have the same
effect as having EnableClientScr ipt set to false on the ASP page -- the
button's onclick event handler runs to completion even if the validator
detects an error in the field.

Of course instead of using a validator, I could just put some code in
the button's onclick event handler that validates the control myself,
and displays the error and exits if something's wrong, but it's more
elegant to use the built-in validators if possible.

Nov 19 '05 #1
1 1476
I think you are asking how to test if the page is invalid before
saving/redirecting, etc.

*Always* test Page.IsValid is true in your Click event method before saving.
Its not done automatically:

Protected Sub Submit_Click(pa rameters)
If Page.IsValid Then
' your code to save/redirect, etc
End If
End Sub

--- Peter Blum
www.PeterBlum.com
Email: PL****@PeterBlu m.com
Creator of "Profession al Validation And More" at
http://www.peterblum.com/vam/home.aspx

<be*****@peacef ire.org> wrote in message
news:11******** *************@g 49g2000cwa.goog legroups.com...
At
http://www.brainjammer.com/testing/validator_test.aspx
I have a text field where you can enter text, and a button where if you
click the button, it sets the value of a label below it, to display the
text you entered in a text field. There is also a
RequiredFieldVa lidator for the text field so that you get an error if
you leave it blank.

As long as I have EnableClientScr ipt set to true for the
RequiredFieldVa lidator, if I leave the text field blank and click the
button (ignore what the button caption says, "hide this panel" etc.),
the RequiredFieldVa lidator shows, and the text of the label below it
does not get set to blank. i.e., when the validator detects an error
in the field, it stops the other button click handling code from
running, which is what you'd expect.

The problem is that if EnableClientScr ipt for the validator is set to
false (which is how I have it set now), then when you enter blank for
the text field and click the button, the validator still displays,
*but* the text of the label below it also changes to blank. So when
the validator is set to only do server-side validation, it doesn't cut
off the other button click handling code from executing when it detects
an error.

Is there any way to make the validator stop the button's onclick event
code from running if the validator detects an error in the field that's
submitted?

I can just set EnableClientScr ipt to true, but some of our users have
JavaScript turned off in their browser, which appears to have the same
effect as having EnableClientScr ipt set to false on the ASP page -- the
button's onclick event handler runs to completion even if the validator
detects an error in the field.

Of course instead of using a validator, I could just put some code in
the button's onclick event handler that validates the control myself,
and displays the error and exits if something's wrong, but it's more
elegant to use the built-in validators if possible.

Nov 19 '05 #2

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

Similar topics

0
2220
by: Tom Pearson | last post by:
I create controls and validators dynamically dependent on data at runtime. I create the control then the relevant validator(s) for it assigning the Control.ID as the control to validate. These controls and validators are then added to a table for display to the user. This code did seem to work originally, but now does not amd I am stumped as to...
12
45283
by: thomas_jedenfelt_1 | last post by:
Hi everyone, Is the W3C HTML Validator in error when it returns <br /> as valid for HTML 4.01 Strict doctype? In March 2004 , the Validator returned <br />, <hr /> and <img /> as invalid for HTML 4.01 Strict. Liam Quinn said "You can't mix HTML and XHTML. You need to choose one or the other syntax."
2
3890
by: Pham Nguyen | last post by:
Has anyone seen an example of a textbox server control that has built-in client-side validation? I'd like to build a server control that extends the System.Web.UI.WebControls.TextBox class to allow javascript checks for things like valid e-mail addresses or phone numbers (without having to add a separate control for validation). One idea I...
6
21309
by: Paul | last post by:
I am trying to setup a field validator and tried using the control to validate set to a dropdown list box but did not seem to work. Is there anyway to set this up or do you need to use client side validation? Thanks -- Paul G Software engineer.
3
1661
by: Angelos Karantzalis | last post by:
Hi guys, I've a small problem with validators. I'm building a single .aspx file that handles all my form posts. I need to be using ASP.NET validators ( or subclasses thereof ), so what i do to overcome the fact that i don't really know what sort of input controls I'm working with is this: 1) I've got the form description in xml, so I...
8
7816
by: pmud | last post by:
Hi, I am using a compare validator in asp.net application(c# code). This Custom validator is used for comparing a value enterd by the user against the primary key in the SQL database. IF the VALUE ENTERED BY THE USER EXISTS IN THE DB , then THE ERROR MESSAGE OF THE COMPARE VALIDATOR SHOULD BE DISPLAYED. For this, I used the reference...
3
1285
by: tshad | last post by:
I have a page that is very long so I have set it up to page using <div> to display or hide the different pages. When I get to the last page the user submits the page. This works great, except that if one of the validators finds an error and it isn't on the last page, the user won't see it. What I want to do is know that there is an error...
1
1722
by: Sam | last post by:
Hi all, Why can't i create a validatorControl as a child of the control to validate? It doesn't give any errors, but it just won't work (it's not validating). The reason why i want this is that i'm creating a repository of WebControls extended/inherited with my own code for repetative use. For example, i have a: Class CreationDate...
40
5542
by: VK | last post by:
Hi, After the response on my request from W3C I'm still unclear about Tidy vs. Validator discrepansies. That started with <IFRAME> issue, but there is more as I know. Anyway, this very basic HTML page: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Strict//EN" "http://www.w3.org/TR/html401/strict.dtd"> <html> <head>
0
7512
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7438
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...
1
7466
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...
0
7803
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...
0
6036
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5362
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...
0
3475
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1926
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 we have to send another system
1
1051
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.