ASP.NET Persisting dynamically created validation controls across postback

C

Chad Smith

Hi.

I have an asp.net web application written in C# which creates a datasource
consisting of a Name and a list of permissable Values. This datasource is
then bound to a simple repeater, the Name being bound to a label and the
Values being bound to a DropDownList. All works fine.

The next thing I wished to do was tap into the ItemDataBound event to add a
generic "Please Select..." item to each DropDownList, with a value of "0".
From here it was a simple jump to, at the same time, add a required field
validator attached to this control and with a DefaultValue of "0". This
worked absolutely perfectly and as I expected, but since then, I moved it to
a server which was playing up and not emitting the code for the page to use
javascript, which highlighted the fact that the validators weren't being
persisted and put back into the validation stack.

My first thought was to store the current Page.Validators in viewstate and
recreate them on page load, but it didn't like that (must be marked as
serializable, etc). My second thought was to create the validators each time
in ItemCreated, but doing that didn't work, I presume because the link was
only by name and not actually persisted properly.

This is where I'm at, at the moment, any thoughts or ideas are greatly
appreciated. Is this a situation where I simply cannot use the validator
framework? Do I have to go back to good 'ol asp 3.0 methods?

Thanks in advance,

Chad Smith
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top