ASP.NET Multiview Control Validators

ASP.NET Multiview Control Validators

Old forum URL: forums.lhotka.net/forums/t/2197.aspx


Gareth posted on Tuesday, January 23, 2007

When using the Multiview control in ASP.NET such as in the ProjectTracker project in CSLA.NET I'd like to apply a RequiredField validator and RegularExpression validator to the DataView for (Id and Name) fields to ensure that they are entered and that they contain valid data.

The multiview control does not seem to support validators, or at least I can't seem to get them to work with the multiview control.

Has anyone had any success with this?

Regards,
Gareth.

 

SonOfPirate replied on Tuesday, January 23, 2007

The only problems I've had with validators in any of the new "view" controls is establishing a reference to the correct control in the code-beside.  Otherwise, I haven't had any problems.  What are the symptoms you are witnessing?

 

Gareth replied on Tuesday, January 23, 2007

I've simply not even managed to drop a validator on the form and link it to a control. How and where did you drop the validator on the form? And how did you link it up to the controls?

Do you have any examples?

Many thanks,
Gareth.

SonOfPirate replied on Tuesday, January 23, 2007

Ah, sorry, I don't usually work in Design Mode - I prefer direct coding.  There I've had no problem entering the controls.

I don't have VS running but if memory serves me correctly, from the few times I have played in Design Mode, you should be able to drop a View control onto the MultiView then drag-n-drop the controls you want shown onto the View just like you would directly onto the page.  A validator control shouldn't behave any differently.  The other controls in the View should appear when you select the ControlToValidate property in the Properties Window - I'm assuming, I haven't tried that part.

HTH

 

Gareth replied on Tuesday, January 23, 2007

I can drop the validator control (required field validator) on the view itself but I am unable to select any controls to validate. I've now tried adding the validator control to various other sections of the form but I still get the same result - no controls being display in the ControlToValidate dropdown :(

Even if I try and code it in, without using the Visual Studio editor it errors everytime saying that the ControlToValidate field does not exist.

Do you happen to have a snapshot of some code where you are using a validator control and linking it successfully to a field?

 

 

 

RockfordLhotka replied on Tuesday, January 23, 2007

It seems to me that Francesco Balena wrote an article in MSDN about doing this a few months ago. It was kind of a hack... If I recall correctly, he wrote some code in the page that looped through the contents of the ListView and dynamically added validation controls.

Basically you have two options: change your ListView fields all to template fields, or use Francesco's hack.

It is my understanding that if you change your fields to template fields, then the template can contain validation controls along with any other controls. Whether you can do this on the web forms design surface I'm not sure, but you can certainly do it by typing the tags into the aspx page.

Copyright (c) Marimer LLC