views:

655

answers:

1

Hi,

I have an asp.net form with bunch of sections that can be expanded/collapsed and are normally collapsed. Now, most controls on the form have RequiredFieldValidator or some other validators attached. If the user tries to submit the form with required fields not filled out, for m is not submitted but because most sections are normally collapsed, the user doesn't see the validator text (like exclamation mark on the right of a text box) prompting to fix the error. What I want to do is for the controls that fail validation, to expand their parent containers so user could see those failed controls, but for that I need to hook up some client sode javascript that woudl execute when client side validation failed. I haven't foudn any way of doing it - validators naturally dont' expose those "validation events" to hookup to. Of course I can create my custom validators but that would mean rewriting (and duplicating functionality) completely all existing asp.net validators which sounds a big chunk of work.

Any ideas?

Thank you in advance! Andrey

A: 

Here is how I solved a similar issue. For every validator that is added to the accordion, I store the validator id in an array, along with the accordion panel that it is contained in. I then pass this list to the client. I also hook into the OnSubmit event by calling Page.ClientScript.RegisterOnSubmitStatement. The javascript function that executes during the onSubmit first checks to see if the page is valid, if so then it just exits, if not then it loops through the list of validators looking for ones that are not valid, when it finds one, it expands the section associated with that validator.

Daniel
It's an interesting idea! In fact, the page will already have an array of all validators in Page_Validators variable; so I just need to loop over the array and for each failed validator get associated control and expand it's parent container. Sounds like it might work for me! Thanks!
Andrey