sparkle999 Posted November 30, 2003 Posted November 30, 2003 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 Quote
*Experts* mutant Posted November 30, 2003 *Experts* Posted November 30, 2003 If the client supports client-side validation, that is what will be automatically done. Quote
*Gurus* Derek Stone Posted November 30, 2003 *Gurus* Posted November 30, 2003 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] Quote Posting Guidelines
sparkle999 Posted November 30, 2003 Author Posted November 30, 2003 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 Quote
*Experts* mutant Posted November 30, 2003 *Experts* Posted November 30, 2003 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. Quote
sparkle999 Posted November 30, 2003 Author Posted November 30, 2003 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! Quote
*Gurus* Derek Stone Posted November 30, 2003 *Gurus* Posted November 30, 2003 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. Run "aspnet_regiis -c" on the Web server to install the client scripts. They must be missing. Quote Posting Guidelines
sparkle999 Posted November 30, 2003 Author Posted November 30, 2003 Errr... thanks again - you were right. :eek: Hope you don't mind the "newbie" type questions... Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.