473,382 Members | 1,775 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,382 software developers and data experts.

CustomValidator problems.

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 browser. During this
second rebuild, since the data on the page was changed by the user, only 1 of
the CustomValidator's is needed and therefore not constructed and not added.
The curious thing is that after the page is reloaded, if you look at the
html, it contains a definition for both of the CustomValidator's. I've even
had situations where if only one is in the html, it has the ID of the first
and the ErrorMessage & ClientValidationFunction of the second so appears as
a mixture of the two.

This really is very odd and I am hoping that somebody out there might be
able to help.

Thanks in advance.
Jul 22 '05 #1
7 2146
Hello,

Can you post some code to show how the CustomValidator are made and how one
of them are removed after postback? This may help us better undrstand the
problem and find what is going on there.

Regards,

Luke
Jul 22 '05 #2
Hello Luke,

Thanks for the reply and yes fair comment. Below is a synopsis of the code.
One thing to note from your comment that I guess might be the cause of my
problem is that I NEVER remove the customValidator during a postback, I just
dont re-add it during a postback.

To clarify the situation, given the code below, here is what happens.

1) Initial call to OnInit(), dataConfidence is less than
field.ConfidenceThreshold, so ConfigureConfidenceLevelValidation() is called
and the CustomValidator made and added to the scriptPlaceHolder (a
System.Web.UI.WebControls.PlaceHolder). The customValidator appears correctly
oin the html.

2) After the "Apply" button is clicked the page is submitted and IsPostBack
== true. The call to UserCorrectedLowConfidenceField() returns true and
dataConfidence is set to 100. This means that dataConfidence is NOT less than
field.ConfidenceThreshold so ConfigureConfidenceLevelValidation() is NOT
called but the validator still appears in the html when you view the source
on the newly generated page.

Thanks again for your post I appreciate your help.

Regards
Christian

-----------------------------------------------------
Basically the code looks like this:

OnInit()
{
....
.... // Various bit of unrelated code.
....
....

if (IsPostBack)
{
if (UserCorrectedLowConfidenceField(field))
{
dataConfidence = 100;
}
dataValue = Request.Form[field.FieldName];
}

tb = AddTextBox(cell, field, dataValue);

if (dataConfidence < field.ConfidenceThreshold)
{
ConfigureConfidenceLevelValidation(tb, field, dataConfidence);
}
....
.... // Various bit of unrelated code.
....
....

}
private void ConfigureConfidenceLevelValidation(Control tb,
FormFieldsDS.FormFieldsRow field, double dataConfidence)
{
CustomValidator cv = new CustomValidator();
this.Validators.Add(cv);
scriptPlaceHolder.Controls.Add(cv);
cv.ControlToValidate = tb.ID;
cv.ErrorMessage = string.Format("{0}: field has a low confidence level.",
field.FieldName);
cv.Display = ValidatorDisplay.None;
cv.ClientValidationFunction = "confidenceLevelValidation";
}

"[MSFT]" wrote:
Hello,

Can you post some code to show how the CustomValidator are made and how one
of them are removed after postback? This may help us better undrstand the
problem and find what is going on there.

Regards,

Luke

Jul 22 '05 #3
I think you may add a breakpoint in ConfigureConfidenceLevelValidation to
see how many time it was called after postback, I suspect it was called
twice incorrectly and use wrong parameters so that there still two
validator in the HTML code.

Luke

Jul 22 '05 #4
Hi Luke

Thanks again for the response. Before posting this question I spent over a
day debugging this problem and what I noticed is that the function
ConfigureConfidenceLevelValidation () is only called once and the net result
is 2 validators. This is why I am so confused and can see no way that there
should be 2. Do you know if you need to remove these validators? perhaps they
are rebuilt on postback from the viewstate and you have ot remove them.
Saying that, I have had a look at the value of "this.Validators.Count" at the
beginning of OnInit() during the postback and it was zero and at the end of
OnInit() it was one, again odd that 2 appear in the html.

"[MSFT]" wrote:
I think you may add a breakpoint in ConfigureConfidenceLevelValidation to
see how many time it was called after postback, I suspect it was called
twice incorrectly and use wrong parameters so that there still two
validator in the HTML code.

Luke

Jul 22 '05 #5
Hello,

CustomValidator control has a property named "EnableViewState", you may set
it to False in your code (ConfigureConfidenceLevelValidation) to see if it
can help.

Luke

Jul 22 '05 #6
Nice one Luke.
It looks like this was the cause of my problems.
Thanks
Christian

"[MSFT]" wrote:
Hello,

CustomValidator control has a property named "EnableViewState", you may set
it to False in your code (ConfigureConfidenceLevelValidation) to see if it
can help.

Luke

Jul 22 '05 #7
Thank you for update. Glad to hear the problem was resolved.

Luke

Jul 22 '05 #8

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

Similar topics

2
by: Stephen Miller | last post by:
Can the CustomValidator be used to simply report unexpected errors, without requiring Client/Server validation? To explain, say you had a simple text box and button that did a Full-text Search of a...
3
by: Ronan Dodworth | last post by:
Hi there I'm having a little bit of a problem with my customvalidator control. The problem is the javascript runs fine on my local webserver IIS but not when I post it to the web hosting server....
1
by: SMG | last post by:
Hi All. My forms has two textboxes, 1 username, 2 password. Both has requiredfield validator it works fine when there is no input in these textboxes. And the errorMsg is shown in...
0
by: John Bonds | last post by:
I'm having some problems with implementing client-side validation in a user control. Here' my code for the usercontrol: <%@ Control Language="vb" AutoEventWireup="false"...
0
by: ghafranabbas | last post by:
This is how you use the customvalidator control in any INamingContainer interface control (Datagrid, DataList, DataRepeater, etc). 1. In the ItemTemplate, place your customvalidator 2. Set the...
1
by: Beffmans | last post by:
Hi I have defined an customvalidator on my TextBox: function clientvalidate(source, arguments){ { // even number? if (arguments.Value%2 == 0) arguments.IsValid = true; else
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...
1
by: theresa | last post by:
I'm about at my wits end trying to figure out why this isn't working, so I'm hoping one of you can help! I'm sure there must be something simple I'm missing. I have a checkbox on an Asp.NET 2.0...
2
by: Epetruk | last post by:
Hello, I have an ASP.NET page which consists of a button (cmdSave), a label (lblMessage), a text field (txtName) and a custom validator (vldName). vldName is supposed to do both client *and*...
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...
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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...

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.