473,563 Members | 2,653 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Validators on dynamic UserControls

Hi

I am currently having problems with Validators in a user control. I am
creating a wizard sign-up process which have the allocated step
(hyperlinks" at the top of the page. A user can also click
next/previous. Dependant on the current step in the sign-up process I
am loading a new user control as I dont want to have 7-8 pages, just
one page and load the control dynamically.

All is sweet at the moment apart from the validation controls that are
assigned to each user control. Any link that is clicked or button that
is clicked should cause validation on that user control, however I have
performed the following (from another thread)

1. Set EnableClientScr ipt=false on each validator.
2. Set CausesValidatio n=false on each button that submits the page.
This
prevents the Page.Validate() method from begin called automatically by
the
button.
3. In your click event method, you will call the Validate() method on
each
validator that is associated with the submit button. Then you will test
the
IsValid property to be true on each validator before saving.

I am performing this process BUT as I loop on each validate control
with the allocated user control the isValid IS ALWAYS true. I am sure
its something to do with not loading something or just a simple step I
have missed.. I would appreciate any help on this, some code:

private bool Persist() {
//first check whether we have valid data
AddStockCommon ctrl =
(AddStockCommon )this.FindContr ol(String.Forma t("{0}{1}",
ViewState["Context"], ".ascx"));

foreach(Control ct in ctrl.Controls) {
if (ct is BaseValidator) {
BaseValidator validator = (BaseValidator) ct;
validator.Valid ate();

if (!validator.IsV alid) {
return false;
}
}

return true;
}
Many thanks

Richard

Feb 20 '06 #1
3 1932
OK

To anyone out there..... Further investigations yielded no solutions
until I decided to make the validators visible (They were set invisible
as I wanted a summary to appear only).

Setting them Visible suddenly made the client side validators work on
the browser, but I have to say that this looks clunky and totally
unusable, (mabe my designer could do something :))

I am now going to do my own checks on the server upon a post back, as
this will say me time understanding these validators which to all
intents and purposes seem like a last minute thought to .NET 1.1.

I hope they have improved on .NET 2.0, and if anyone can either point
me in the right direction then I'll maybe return to this validation
technique but for now its easier (on the eye and technically) to
perform all validation server side...

If anyone can tell me why setting these validators Invisible affects
how they work then I would be glad to hear.

Many thanks

Richard

Feb 21 '06 #2
Check out the image in this article. They talk about the same thing,
that the validation summary is ugly.

http://www.codeproject.com/aspnet/vsum.asp

There may be a solution here as well
http://www.asp101.com/articles/manu/...ry/default.asp

jp
rg*******@hotma il.com wrote:
OK

To anyone out there..... Further investigations yielded no solutions
until I decided to make the validators visible (They were set invisible
as I wanted a summary to appear only).

Setting them Visible suddenly made the client side validators work on
the browser, but I have to say that this looks clunky and totally
unusable, (mabe my designer could do something :))

I am now going to do my own checks on the server upon a post back, as
this will say me time understanding these validators which to all
intents and purposes seem like a last minute thought to .NET 1.1.

I hope they have improved on .NET 2.0, and if anyone can either point
me in the right direction then I'll maybe return to this validation
technique but for now its easier (on the eye and technically) to
perform all validation server side...

If anyone can tell me why setting these validators Invisible affects
how they work then I would be glad to hear.

Many thanks

Richard


Feb 22 '06 #3
By definition, when any web control has Visible=false, that turns off the
control. It will not generate anything to the client-side. It isn't a style
that shows and hide things. (Besides the validators have the job of showing
and hiding themselves.) Since the validator is off when Visible=false, the
call to Validator.Valid ate() or even Page.Validate() will do nothing to the
validator.

Recommendation: Use Validation Groups, one for each page. This comes with
ASP.NET 2.0 and my Professional Validation And More
(http://www.peterblum.com/vam/home.aspx) which works with all versions of
ASP.NET.
Setting them Visible suddenly made the client side validators work on
the browser, but I have to say that this looks clunky and totally
unusable, (mabe my designer could do something :))

If you set EnableClientScr ipt=false on each validator, there should be no
client-side validation. Confirm these settings.
What does "looks clunky" mean? One guess is that validators are changing
their spacing on the screen, moving things around. Use
Validator.Displ ay=Static or set the Text property to "*" and add a
ValidationSumma ry to show the actual error.

--- Peter Blum
www.PeterBlum.com
Email: PL****@PeterBlu m.com
Creator of "Profession al Validation And More" at
http://www.peterblum.com/vam/home.aspx

<rg*******@hotm ail.com> wrote in message
news:11******** **************@ g14g2000cwa.goo glegroups.com.. . Hi

I am currently having problems with Validators in a user control. I am
creating a wizard sign-up process which have the allocated step
(hyperlinks" at the top of the page. A user can also click
next/previous. Dependant on the current step in the sign-up process I
am loading a new user control as I dont want to have 7-8 pages, just
one page and load the control dynamically.

All is sweet at the moment apart from the validation controls that are
assigned to each user control. Any link that is clicked or button that
is clicked should cause validation on that user control, however I have
performed the following (from another thread)

1. Set EnableClientScr ipt=false on each validator.
2. Set CausesValidatio n=false on each button that submits the page.
This
prevents the Page.Validate() method from begin called automatically by
the
button.
3. In your click event method, you will call the Validate() method on
each
validator that is associated with the submit button. Then you will test
the
IsValid property to be true on each validator before saving.

I am performing this process BUT as I loop on each validate control
with the allocated user control the isValid IS ALWAYS true. I am sure
its something to do with not loading something or just a simple step I
have missed.. I would appreciate any help on this, some code:

private bool Persist() {
//first check whether we have valid data
AddStockCommon ctrl =
(AddStockCommon )this.FindContr ol(String.Forma t("{0}{1}",
ViewState["Context"], ".ascx"));

foreach(Control ct in ctrl.Controls) {
if (ct is BaseValidator) {
BaseValidator validator = (BaseValidator) ct;
validator.Valid ate();

if (!validator.IsV alid) {
return false;
}
}

return true;
}
Many thanks

Richard

Feb 23 '06 #4

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

Similar topics

1
303
by: Jim Heavey | last post by:
Hello I have a DataList control with a couple of text boxes and a couple of RequiredField Validators and Regular Expression Validators, but they are not doing anything. When I blank out the value in the field, neither of the Required field validators are posting an error. I set the "causesValidation" property on the button to "true". What...
1
1149
by: tshad | last post by:
Is there a way to tell the validators to not fire if one of the validators fails the input? For example: In the following code, if someone doesn't enter anything in the field, I should get the message " A password must be entered". I am also getting the message that I need " 1 numeric", "the passwords don't match" and "I need from 6 -...
7
1883
by: Abraham Luna | last post by:
how do i stop the dynamic validators from breaking explorer if i use a dynamic validator and move to a different control it breaks explorer and i can type in the page when i'm not supposed to. thank you.
2
1725
by: Mike Surcouf | last post by:
Hi I have some regex validators on my page set to dynamic and like the way they appear after you tab out of a field and also when you try to postback the form. All OK so far When I register for the client side event of a textbox using ... textBox.Attributes.Add("onKeyUp","javascriptfunction");
0
969
by: tshad | last post by:
I have the following textbox and 3 validators. For some reason the message "A Password is required!" is displayed with a couple of spaces in front of it. My other validators don't seem to do this. They are all set to Dynamic. <asp:textbox id="Password" TextMode="Password" Columns="25" runat="server" /> <asp:RegularExpressionValidator...
1
2346
by: Gummy | last post by:
Hello, I am loading several user controls dynamically in OnInit() like this: ucListBoxSelections ucLocation = (ucListBoxSelections)LoadControl("UserControls/ucListBoxSelections.ascx");
0
320
by: Mike Collins | last post by:
I have a form where I create dynamic controls at runtime. With this, I am adding a dynamic required field validators to each control as needed, but the validators are not firing when I click submit. The submit button was placed at design time and its causesvalidation property is set to true. Can someone tell me if something is missing from my...
5
1536
by: shapper | last post by:
Hello, Is there any way to make ASP.NET validators to display as block? I tried everything I could think off with skins, css, etc. I really don't know what else to try. Shouldn't this be easy? The objective is "only" to display the validators message in a single line.
0
875
by: Nathan Sokalski | last post by:
I have a UserControl that contains Controls I want to validate. I am attempting to write a class that inherits BaseValidator (which I have done many times before for the standard controls such as TextBox) to do this validation. I have added properties to my UserControl that make the properties necessary to do validation available, so...
0
7664
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...
0
7583
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7885
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. ...
0
8106
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...
1
7638
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...
0
6250
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...
0
5213
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...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1198
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.