473,800 Members | 2,404 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Validators not preventing postbacks

AD
Hi,

I have 2 different web pages, both using RequiredFieldVa lidator'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 6543
Hi there,

First if you want to prevent the post from the client browser set
EnableClientScr ipt 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 MyInsertButtonC lick(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 RequiredFieldVa lidator'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 EnableClientScr ipt 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 "CausesValidati on" 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 "CausesValidati on" = True.
"AD" <ad**********@y ahoo.co.ukwrote in message news:11******** **************@ n59g2000hsh.goo glegroups.com.. .
Hi Milosz,

Thanks for the response.

Both EnableClientScr ipt 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 CausesValidatio n 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 EnableClientScr ipt 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
2021
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 why. There have been some code changes, but not to the methods below and I have pretty much...
0
1914
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 why. There have been some code changes, but not to the methods below and I have pretty much...
6
1624
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 have a default RED font that appears to be difficult to remove. We could hard code in a blank font color into the .aspx html for each validator, but that would defeat the purpose of the CSS. Is there a way to change the default RED color of...
3
1873
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 validators on the page fire which i don't want - i've tried to make them invisible - this hides the controls but i get a strange error when i click the Update column - i tried to disable them - they become disabled but i can see my error "*" appearing next...
1
2115
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 couple things I need to check: 1) tbxYear1 and tbxYear2 are both optional, but if values are entered they have to integers and non-negative 2) if values are entered for both tbxYear1 and tbxYear2 then tbxYear1 must be less than tbxYear2 It...
1
2065
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 dynamically, for some of the inserted controls. The controls (e.g., textBoxes) get created correctly and viewstate is maintained across postbacks, etc - BUT there is an issue with the validation controls. The validation controls, themselves are...
1
1664
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 the currently selected pageview of the multipage. To prevent this from happening I disable all the validators and only enable the validators on the selected page but does not look to me like the correct way of working. Is there a better way to...
1
1332
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 page without clicking the submit button the validators are executed, preventing the user from leaving the page. How can I resolve this? Thanks
12
2154
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 spam. I would imagine they're using the HttpWebRequest method for this. Essentially, it would require a property on a WebForm that indicates whether it is *only* for PostBack (true by default, but configurable), which would
0
9690
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10505
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
10275
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10253
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
10033
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...
0
9085
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6811
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
5606
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3764
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.