473,722 Members | 2,484 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Having problems with validators

Having a problem with validators.

Because we want to only test whether the current field in a changed event is valid before we process the change code, I have tried
to turn off all validators for the page (all ctrls are in a table), then just enable the one relevant validator, run the
page.validate and then if valid, do the change code. otherwise, skip the change code and then finally enable all the validators
again.

What's happening is that it all seems to work except that if the field fails validation, the page isn't displaying the error
message.. until I change the field again. So on first postback, the error doesn't display, but on 2nd postback it does.

The validator does contain the expected error message and IsValid value after each postback.

'-----------------------------------------------
Public Sub ToggleValidator s(ByVal bToggle As Boolean)
Dim bv As BaseValidator
For Each bv In Page.Validators
bv.Enabled = bToggle
Next
End Sub

'Child changed event..
Dim cv As CustomValidator
ToggleValidator s(False)

cv = mytable.FindCon trol(ID + "_validator ")
If Not cv Is Nothing Then cv.Enabled = True

Page.Validate()
If Page.IsValid Then
' changed event handling for control ID.
End If

ToggleValidator s(True)
'-----------------------------------------------

Hope someone can spot what's wrong with this.

Thanks
--
Adrian Parker
Ingenuity At Work Ltd
Mar 7 '06 #1
7 1228
DWS
Adrian,

I'd try in addtion to turning on the validator to send an error message to
the client. Add a simple label to contain the error message. Cool technique
I'm going to try it I have so much trouble with validators not letting my
code run that I hardly ever use them.

Please do me a favor and vote for one of my entries at.
http://blog.mix06.com/contest/gallery/default.aspx
"The Hand is Quicker Than The Eye" or "Software"

Thank you and Good Luck
DWS

"Adrian Parker" wrote:
Having a problem with validators.

Because we want to only test whether the current field in a changed event is valid before we process the change code, I have tried
to turn off all validators for the page (all ctrls are in a table), then just enable the one relevant validator, run the
page.validate and then if valid, do the change code. otherwise, skip the change code and then finally enable all the validators
again.

What's happening is that it all seems to work except that if the field fails validation, the page isn't displaying the error
message.. until I change the field again. So on first postback, the error doesn't display, but on 2nd postback it does.

The validator does contain the expected error message and IsValid value after each postback.

'-----------------------------------------------
Public Sub ToggleValidator s(ByVal bToggle As Boolean)
Dim bv As BaseValidator
For Each bv In Page.Validators
bv.Enabled = bToggle
Next
End Sub

'Child changed event..
Dim cv As CustomValidator
ToggleValidator s(False)

cv = mytable.FindCon trol(ID + "_validator ")
If Not cv Is Nothing Then cv.Enabled = True

Page.Validate()
If Page.IsValid Then
' changed event handling for control ID.
End If

ToggleValidator s(True)
'-----------------------------------------------

Hope someone can spot what's wrong with this.

Thanks
--
Adrian Parker
Ingenuity At Work Ltd

Mar 7 '06 #2
Hi Adrian,

As for the ASP.NET web pages, are you developing through ASP.NET 1.1 or
ASP.NET 2.0? As for ASP.NET 2.0, we can use the ValiationGroup to separate
different part of control on the pages to be validated through different
set of validators (and be triggered by different submit buttons). Therefore
I think you can configure those validtors you do not want to be validting
when post back(but let your own code to perform the valiation) to be a
different valiationgroup name. In addition, for the ASP.NET valiation
control, we can call the "Validate" method on an individual validator
instead of call validate method of the entire page, and check the IsValid
property on the validator control. I think this'll make the task much
simpler? for example:
protected void btnPost_Click(o bject sender, EventArgs e)
{
Response.Write( "<br/>Normal Postback...");

Response.Write( "<br/>RequiredFieldV alidator3.IsVal id: " +
RequiredFieldVa lidator3.IsVali d);

this.RequiredFi eldValidator3.V alidate();

Response.Write( "<br/>RequiredFieldV alidator3.IsVal id: " +
RequiredFieldVa lidator3.IsVali d);
}
Hope this helps.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Mar 8 '06 #3
Sorry no, v1.1 in this case.

"Steven Cheng[MSFT]" <st*****@online .microsoft.com> wrote in message news:7C******** ******@TK2MSFTN GXA03.phx.gbl.. .
Hi Adrian,

As for the ASP.NET web pages, are you developing through ASP.NET 1.1 or
ASP.NET 2.0? As for ASP.NET 2.0, we can use the ValiationGroup to separate
different part of control on the pages to be validated through different
set of validators (and be triggered by different submit buttons). Therefore
I think you can configure those validtors you do not want to be validting
when post back(but let your own code to perform the valiation) to be a
different valiationgroup name. In addition, for the ASP.NET valiation
control, we can call the "Validate" method on an individual validator
instead of call validate method of the entire page, and check the IsValid
property on the validator control. I think this'll make the task much
simpler? for example:
protected void btnPost_Click(o bject sender, EventArgs e)
{
Response.Write( "<br/>Normal Postback...");

Response.Write( "<br/>RequiredFieldV alidator3.IsVal id: " +
RequiredFieldVa lidator3.IsVali d);

this.RequiredFi eldValidator3.V alidate();

Response.Write( "<br/>RequiredFieldV alidator3.IsVal id: " +
RequiredFieldVa lidator3.IsVali d);
}
Hope this helps.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Mar 8 '06 #4
Never Mind, the validation technique works fine on a test screen, just not on the page I'm trying to use it on.

"Adrian Parker" <ap******@nospa m.nospam> wrote in message news:eS******** ******@TK2MSFTN GP11.phx.gbl...
Sorry no, v1.1 in this case.

"Steven Cheng[MSFT]" <st*****@online .microsoft.com> wrote in message news:7C******** ******@TK2MSFTN GXA03.phx.gbl.. .
Hi Adrian,

As for the ASP.NET web pages, are you developing through ASP.NET 1.1 or
ASP.NET 2.0? As for ASP.NET 2.0, we can use the ValiationGroup to separate
different part of control on the pages to be validated through different
set of validators (and be triggered by different submit buttons). Therefore
I think you can configure those validtors you do not want to be validting
when post back(but let your own code to perform the valiation) to be a
different valiationgroup name. In addition, for the ASP.NET valiation
control, we can call the "Validate" method on an individual validator
instead of call validate method of the entire page, and check the IsValid
property on the validator control. I think this'll make the task much
simpler? for example:
protected void btnPost_Click(o bject sender, EventArgs e)
{
Response.Write( "<br/>Normal Postback...");

Response.Write( "<br/>RequiredFieldV alidator3.IsVal id: " +
RequiredFieldVa lidator3.IsVali d);

this.RequiredFi eldValidator3.V alidate();

Response.Write( "<br/>RequiredFieldV alidator3.IsVal id: " +
RequiredFieldVa lidator3.IsVali d);
}
Hope this helps.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)


Mar 9 '06 #5
Hi Adrian,

I've also tried the approch in an ASP.NET 1.1 application on myside and it
works. We can just set the validator's "Enabled" to false initially. And
only reenable it at runtime(in postback event) when we want to perform the
validation. For example:
private void btnThree_Click( object sender, System.EventArg s e)
{

rfvThree.Enable d = true;
Response.Write( "<br/>rfvThree.IsVal id: " + rfvThree.IsVali d);

rfvThree.Valida te();

Response.Write( "<br/>rfvThree.IsVal id: " + rfvThree.IsVali d);

rfvThree.Enable d = false;

}

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Mar 9 '06 #6
Hi Steven,

Excellent, that works well. In addition, I just needed to enable all the validators on the page at the top of any form submit events
before calling the page.validate() there.

Many Thanks
--
Adrian Parker
Ingenuity At Work Ltd

"Steven Cheng[MSFT]" <st*****@online .microsoft.com> wrote in message news:CC******** ******@TK2MSFTN GXA03.phx.gbl.. .
Hi Adrian,

I've also tried the approch in an ASP.NET 1.1 application on myside and it
works. We can just set the validator's "Enabled" to false initially. And
only reenable it at runtime(in postback event) when we want to perform the
validation. For example:
private void btnThree_Click( object sender, System.EventArg s e)
{

rfvThree.Enable d = true;
Response.Write( "<br/>rfvThree.IsVal id: " + rfvThree.IsVali d);

rfvThree.Valida te();

Response.Write( "<br/>rfvThree.IsVal id: " + rfvThree.IsVali d);

rfvThree.Enable d = false;

}

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Mar 9 '06 #7
You're welcome Adrian,

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Mar 9 '06 #8

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

Similar topics

1
2020
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
1910
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...
7
2176
by: jcpmeticulus | last post by:
Hi I've spent the last day or so debugging a problem with a CustomValidator and am now totally stumped! Basically I use a number of CustomValidator's on my page, but have cut this down now to only 2. When the page is first loaded the CustomValidator are made and the generated HTML contains both of them. When the "Apply" button is clicked the page is posted back and my database is updated. The page is then rebuilt and sent back to the...
6
1621
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...
1
1285
by: John Slate | last post by:
I have built a simple form that uses input validation. I use the EnableClientScript option to produce a javascript alert box when input errors occur. The only validation is a password confirmation which uses a compare validator and a validation summary. On my local machine, this form performs as designed. However, when deployed on a live server the input validation no longer works. Any suggestions as to why this may be happening? Thanks!
3
1868
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
2113
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
1663
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
1202
by: JimCinLA | last post by:
I have Requierd Field validators with several controls on a form. The Requires Validation property on the fields are set to True. In Debug mode, the validators work as expected. If the fields are left blank, then the warning message is displayed when the form is submitted. But the behavior changes when the project is deployed. The validators don't work any more. Any clues to what's happening?
0
8863
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...
1
9157
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
9088
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
8052
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...
1
6681
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5995
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
4762
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3207
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
3
2147
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.