473,756 Members | 1,764 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 & ClientValidatio nFunction 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 2176
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.Confidenc eThreshold, so ConfigureConfid enceLevelValida tion() is called
and the CustomValidator made and added to the scriptPlaceHold er (a
System.Web.UI.W ebControls.Plac eHolder). The customValidator appears correctly
oin the html.

2) After the "Apply" button is clicked the page is submitted and IsPostBack
== true. The call to UserCorrectedLo wConfidenceFiel d() returns true and
dataConfidence is set to 100. This means that dataConfidence is NOT less than
field.Confidenc eThreshold so ConfigureConfid enceLevelValida tion() 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 (UserCorrectedL owConfidenceFie ld(field))
{
dataConfidence = 100;
}
dataValue = Request.Form[field.FieldName];
}

tb = AddTextBox(cell , field, dataValue);

if (dataConfidence < field.Confidenc eThreshold)
{
ConfigureConfid enceLevelValida tion(tb, field, dataConfidence) ;
}
....
.... // Various bit of unrelated code.
....
....

}
private void ConfigureConfid enceLevelValida tion(Control tb,
FormFieldsDS.Fo rmFieldsRow field, double dataConfidence)
{
CustomValidator cv = new CustomValidator ();
this.Validators .Add(cv);
scriptPlaceHold er.Controls.Add (cv);
cv.ControlToVal idate = tb.ID;
cv.ErrorMessage = string.Format(" {0}: field has a low confidence level.",
field.FieldName );
cv.Display = ValidatorDispla y.None;
cv.ClientValida tionFunction = "confidenceLeve lValidation";
}

"[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 ConfigureConfid enceLevelValida tion 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
ConfigureConfid enceLevelValida tion () 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.Validator s.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 ConfigureConfid enceLevelValida tion 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 "EnableViewStat e", you may set
it to False in your code (ConfigureConfi denceLevelValid ation) 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 "EnableViewStat e", you may set
it to False in your code (ConfigureConfi denceLevelValid ation) 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
2412
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 Catalogue in SQL. Malformed search requests can generate a variety of errors, which I simply want to catch, set the CustomValidator's IsValid method to false and assign the ErrorMessage to the CustomValidator's Message property. For example: ...
3
1754
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. As it is client side scripting I'm suprised that this is the case as I'm using the same browser IE6 and the same machine to access both. I've included the code below. Can anyone help . I've tried lowering all the security settings for intranet...
1
1847
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 ValidationSummary. Now I want to check the username should contain only chatacters, ( I want to use customvalidator), when i enter char+number it trap the event of customvalidator but it doesn't show the errormsg in the customValidator and submits the form.
0
1456
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" Codebehind="uclPayment.ascx.vb" Inherits="maestroglass.uclPayment" TargetSchema="http://schemas.microsoft.com/intellisense/ie5" %> <script language="vbscript"> Sub ValidateExpirationDate(source, args) 'MsgBox(document.forms) Dim pFormDate As Date = DateValue("1/" &
0
3537
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 OnServerValidate property of the customvalidator 3. Get reference to the Data Item object (For DataList is DataListItem, for DataGrid its DataGridItem) 4. Get reference to any controls needed for validation 5. Perform the validation
1
2491
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
402
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...
1
6123
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 web form that needs to be checked before the form is successfully submitted. I've done the same thing on an Asp.NET 1.1 form before and had no problems, but using the exact same code on the 2.0 form absolutely nothing happens. No errors of any...
2
1612
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* server validation of txtName; the custom validation function is ValidateName, and the server validation function is ValidateNameOnServer. This validation should occur when cmdSave is clicked. If no text has been
0
9455
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
10031
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
9869
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
9838
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
8709
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
7242
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
5140
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3805
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
2665
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.