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

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 ToggleValidators(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
ToggleValidators(False)

cv = mytable.FindControl(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

ToggleValidators(True)
'-----------------------------------------------

Hope someone can spot what's wrong with this.

Thanks
--
Adrian Parker
Ingenuity At Work Ltd
Mar 7 '06 #1
7 1215
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 ToggleValidators(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
ToggleValidators(False)

cv = mytable.FindControl(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

ToggleValidators(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(object sender, EventArgs e)
{
Response.Write("<br/>Normal Postback...");

Response.Write("<br/>RequiredFieldValidator3.IsValid: " +
RequiredFieldValidator3.IsValid);

this.RequiredFieldValidator3.Validate();

Response.Write("<br/>RequiredFieldValidator3.IsValid: " +
RequiredFieldValidator3.IsValid);
}
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**************@TK2MSFTNGXA03.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(object sender, EventArgs e)
{
Response.Write("<br/>Normal Postback...");

Response.Write("<br/>RequiredFieldValidator3.IsValid: " +
RequiredFieldValidator3.IsValid);

this.RequiredFieldValidator3.Validate();

Response.Write("<br/>RequiredFieldValidator3.IsValid: " +
RequiredFieldValidator3.IsValid);
}
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******@nospam.nospam> wrote in message news:eS**************@TK2MSFTNGP11.phx.gbl...
Sorry no, v1.1 in this case.

"Steven Cheng[MSFT]" <st*****@online.microsoft.com> wrote in message news:7C**************@TK2MSFTNGXA03.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(object sender, EventArgs e)
{
Response.Write("<br/>Normal Postback...");

Response.Write("<br/>RequiredFieldValidator3.IsValid: " +
RequiredFieldValidator3.IsValid);

this.RequiredFieldValidator3.Validate();

Response.Write("<br/>RequiredFieldValidator3.IsValid: " +
RequiredFieldValidator3.IsValid);
}
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.EventArgs e)
{

rfvThree.Enabled = true;
Response.Write("<br/>rfvThree.IsValid: " + rfvThree.IsValid);

rfvThree.Validate();

Response.Write("<br/>rfvThree.IsValid: " + rfvThree.IsValid);

rfvThree.Enabled = 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**************@TK2MSFTNGXA03.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.EventArgs e)
{

rfvThree.Enabled = true;
Response.Write("<br/>rfvThree.IsValid: " + rfvThree.IsValid);

rfvThree.Validate();

Response.Write("<br/>rfvThree.IsValid: " + rfvThree.IsValid);

rfvThree.Enabled = 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
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...
7
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...
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...
1
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...
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: 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: 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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: 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
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...
0
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...

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.