473,324 Members | 2,356 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,324 software developers and data experts.

Validators not preventing postbacks

AD
Hi,

I have 2 different web pages, both using RequiredFieldValidator's, on
the one page Postbacks are prevented when required fields are blank,
on the other page the validators display the error messages after the
postback has returned, but neither the client side, nor the server
side processing is suppressed (my incomplete data is written to my
table)

Any idea what could be wrong?

Apr 18 '07 #1
4 6503
Hi there,

First if you want to prevent the post from the client browser set
EnableClientScript to true. Second, we can't rely on client script validation
as it's very easy to prepare a page that simply skips it. Anyway, the problem
is you don't check IsValid property before executing database insertion code.
Valdators do not prevent page execution automatically (apart from client
side), therefore before you perfom any action, you need to check if page
passed validation (in other words, if all the validators are valid):

protected void MyInsertButtonClick(object sender, EventArgs e)
{
if (this.IsValid)
{
// insert data to database
}
}

Hope this helps
--
Milosz
"AD" wrote:
Hi,

I have 2 different web pages, both using RequiredFieldValidator's, on
the one page Postbacks are prevented when required fields are blank,
on the other page the validators display the error messages after the
postback has returned, but neither the client side, nor the server
side processing is suppressed (my incomplete data is written to my
table)

Any idea what could be wrong?

Apr 18 '07 #2
AD
Hi Milosz,

Thanks for the response.

Both EnableClientScript and Enabled is true on the Validator control,
on both pages, on the one page the postback is prevented, on the other
it is not, anything else I can check?

Apr 18 '07 #3


check that the db update control has the "CausesValidation" property set to True.

Check the validation group, the db update button(or what ever control you are using) and validation should have the same validation group or they both should have no validation if required.

if non of the bove worked use Page.Validate() in the click event for the db update button, but u don't need to do that if "CausesValidation" = True.
"AD" <ad**********@yahoo.co.ukwrote in message news:11**********************@n59g2000hsh.googlegr oups.com...
Hi Milosz,

Thanks for the response.

Both EnableClientScript and Enabled is true on the Validator control,
on both pages, on the one page the postback is prevented, on the other
it is not, anything else I can check?

Apr 18 '07 #4
Make sure you check the button has got CausesValidation set to true, and the
code tests for IsValid in button's event handler:

if (Page.IsValid)
{
// collect values and insert into a databse
}

hope this helps
--
Milosz
"AD" wrote:
Hi Milosz,

Thanks for the response.

Both EnableClientScript and Enabled is true on the Validator control,
on both pages, on the one page the postback is prevented, on the other
it is not, anything else I can check?

Apr 18 '07 #5

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

Similar topics

1
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...
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...
6
by: Mark | last post by:
We have Validators embedded in an asp table server control. The table server control is necessary and cannot be replaced. We want to apply CSS formatting to the validators, but the validators...
3
by: John Blair | last post by:
Hi, I have validators outside of a datagrid (for adding a new grid row) - however when i click "edit" column and then the "update" column of a grid row that has been edited - my other...
1
by: epigram | last post by:
I'm trying to use the ASP.NET validators to check some client-side business rules. I've got two ASP TextBox controls (call them tbxYear1 and tbxYear2) used to enter a range of years. I've got a...
1
by: Jeffrey Todd | last post by:
I have successfully created functionality that mostly models what I'm trying to do - which is dynamically insert controls into a user control (ascx), and insert validation controls, also...
1
by: Gabriel Lozano-Morán | last post by:
When using the tabstrip control combined with a multipage (several pageview) there is a problem when using validators. The problem is that validation also occurs on the validators that are not on...
1
by: Chris | last post by:
Hi, I have a few validators (RequiredFieldValidators) on a page. It works great the user clicks the submit button, the problem I have is when the user goes to the page and then tries to leave the...
12
by: Mark Rae | last post by:
Hi, See the previous thread Request.Form abuse in this newsgroup... I'm looking for a simple and efficient way to prevent people hijacking the <formtags on my websites and using them to send...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.