473,387 Members | 1,603 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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
RequiredFieldValidator for the text field so that you get an error if
you leave it blank.

As long as I have EnableClientScript set to true for the
RequiredFieldValidator, if I leave the text field blank and click the
button (ignore what the button caption says, "hide this panel" etc.),
the RequiredFieldValidator 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 EnableClientScript 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 EnableClientScript to true, but some of our users have
JavaScript turned off in their browser, which appears to have the same
effect as having EnableClientScript 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 1459
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(parameters)
If Page.IsValid Then
' your code to save/redirect, etc
End If
End Sub

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

<be*****@peacefire.org> wrote in message
news:11*********************@g49g2000cwa.googlegro ups.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
RequiredFieldValidator for the text field so that you get an error if
you leave it blank.

As long as I have EnableClientScript set to true for the
RequiredFieldValidator, if I leave the text field blank and click the
button (ignore what the button caption says, "hide this panel" etc.),
the RequiredFieldValidator 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 EnableClientScript 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 EnableClientScript to true, but some of our users have
JavaScript turned off in their browser, which appears to have the same
effect as having EnableClientScript 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
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...
12
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...
2
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...
6
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...
3
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...
8
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...
3
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...
1
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...
40
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
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...

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.