Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi all,

 

I have a simple web form whereby I want to hide certain fields from the user until they have completed other fields and validation has succeeded.

 

Currently I have achieved this using validator controls and validating on the server side. The trouble with this is that everytime the user enters something into one of these fields, it has to do a round-trip to the server and back - and redraw the whole page, which isn't pretty.

 

Is the best bet for me to look at something along the lines of Java code that could run on the client? Or does dot net provide facilities that I could use. The key thing is I don't want to stop 99% of browsers from using my web application.

 

Any assistance would be appreciated

Cheers

  • *Gurus*
Posted

What validator type are you using? Client-side script should be getting generated automatically for each control that requires it.

 

The only exception is for custom validators where you'll need to specify the JavaScript function with the ClientValidationFunction property of the validator control.

 

[msdn]System.Web.UI.WebControls.CustomValidator[/msdn]

Posted

Thanks for your comments - I appreciate your help with this.

 

For your information, I'm new to this game - my background is C/UNIX/Oracle - so apologies if I'm asking daft questions.

 

The validators in question aren't anything special - a compare validator, a range validator and a required field validator.

 

I've played around with the "enableclientscript" settings, clienttarget settings and also the validator.display settings and I now think I understand these better than I did previously.

 

I can get an *individual* validator to display it's error message without posting back to the server.

 

Two things:

 

(1) It would be better to consolidate all error messages and display in a single text label - I can do this by writing code behind a button_click event - to loop through all the validators and concatenate all error messages. I can't see an obvious way of doing this client-side;

 

(2) I want to be able to make certain text fields visible depending upon what has been picked from a drop-down box. So if the user picks item 1 from the box, field A appears, if the user picks item 2 from the box, field B appears, and if the user picks item 3 from the box, fields A and B appear. I can provide this functionality server side by writing code behind the SelectedIndexChanged event for the dropdown box - but again this involves a round trip and a flicker on the screen. I can't see an obvious way of doing this client-side.

 

Thanks again for the help thus far - you've nudged me along in the right direction!

 

Cheers

  • *Experts*
Posted
As for number 1, put a ValidationSummary control on your page. The ValidationSummary will take any error that the user has made and display all of them. From the properties select the DisplayMode property and set it to SingleParagraph. This will make it look like a single label.
Posted

Many thanks for that! I've implemented this on my development PC (which also acts as a web server) and it worked a treat. Strangely, the client validation doesn't seem to work when I upload the same application to a central web server. There must be a setting somewhere I've not spotted. Anyway, thanks again - I'm sure I'll crack that problem myself...

 

If anyone has any ideas on problem (2) I would be most grateful!

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...