Forums: Back End:

 

.NET validation controls in combination

first
 

scudsucker .NET validation controls in combination

Hi,

I have taken over a really messy C#.NET website with several lengthy forms.

Each one has multiple possible paths, and I have been asked to ensure that a user enters data in all fields (all are required)

A typical form would have the following (reduced) structure:


1) What vehicle do you drive?
a) Car
b) Motrobike

If a) What make is it?
If b) What is the odometer reading

2) Do you
a) rent or
b) own your own house?

If a) How much do you pay?
If b) How many bedrooms does it have



The format is generally a radio button for the "top level" question, and textbox input for the "secondary level"

So a possible answer for question 1 would be that I have a Motorbike, and have travelled 100km, etc.


Now, is there a way to combine validation controls in order to ensure that if I check the radio button for "Motorbike", I am required to answer the odometer reading, but not the make?

The only way I can see to do this is very very tedious javascript- especially as the forms are up to 10 or 20 questions.

Is there a better way?


// --------------------------------------------------------------------------------

OR....

Is there a way to target a control on a page in a simalar way to flash eg, I have several text controls with IDs in the format "txt1Name", "txt2Name", "txt3Name" - is there a way to target them like so:

for(Int32 i=0; i<=5; i++) {
string s=Page["txt" + i + "Name"].Text;
// do something with s here
}


Later edit - ok, suddenly remembered "eval" from flash 4 and 5; did a google for C# version of eval and got Page.FindControl() which looks very promising.


 

jamiec

The way I do this is to have the radio-buttons postback and make visible/invisible an asp Placeholder with the additional question + validation control. If an asp placeholder is invisible the validation controls inside it dont get evaluated so it all works exactly as you want.

Does that make sense? If not i'll knock up some example markup for you.

 

scudsucker

Yes, that's more or less how i would go about it.

However, the forms have been so badly coded - both the HTML and the back-end, I would have to re-do the entire 6000+ lines of tedious code...

So I am doing it old-school, "if" statements, luckily much can be reduced to simple functions that return true/false

Bah!

 
first
 

Forums: Back End: .NET validation controls in combination

 
New Post
 
You must be logged in to post