473,396 Members | 2,129 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

ASP.NET Persisting dynamically created validation controls across postback

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
Jan 8 '06 #1
1 1442
On 08/01/2006 18:45:38, "Chad Smith" wrote:
Hi.
Solution found - reply if you wish me to elaborate on this.

Chad.
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


Jan 8 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Tomas Vera | last post by:
Here's another goofy thing. I need to persist the state of items added dynamically to a Panel control between round-trips to the server. I have a web form that contains a TreeView and a...
1
by: Gopal Krish | last post by:
I'm have coded a simple menu (using link buttons as menu items) in a user control to be reused across many ASPX pages. In the page_load method I dynamically create the link buttons as follows ...
3
by: Stu | last post by:
Hi, I am creating a control in a PlaceHolder like so: Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click Dim ctrl As...
1
by: Jeffrey Todd | last post by:
I have successfully created functionality that mostly models what I'm trying to do - which is dynamically insert controls into a user control (ascx), and insert validation controls, also...
1
by: Marcus | last post by:
I have a problem maybe one of you could help me with. I've created a data entry screen with lots of dynamically-created client-side controls. I create HTML texboxes client-side by assigning a...
2
by: xenophon | last post by:
I added a Hidden Form Field to a form in the code behind. The value is being set in JavaScript client-side, but it is not persisting to the server in the PostBack. I know the value is being set...
2
by: Velislav | last post by:
Hi, I have the following scenario: A data-bound repeater, in which every item registers a hidden field with the item's associated ID (a field pulled out of the database) using the...
9
by: Chris | last post by:
I am dynamically adding a user control to each row in a gridview. The reason I am doing it dynamically is the user control is different depending on certain data in the gridview. The gridview...
4
by: Lewis Holmes | last post by:
Hi I have the following situation in one of my asp.net pages. The user can add multiple table rows to a form by selecting a button. These rows can contain asp.net controls. When this button is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.