This is a migrated thread and some comments may be shown as answers.

Grid - Edit Control - User Control ViewState

1 Answer 20 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jeff Taynton
Top achievements
Rank 1
Jeff Taynton asked on 10 Aug 2012, 10:21 PM
We have a custom user control (let's say Prices.ascx) which is responsible for dynamically creating a number of RadNumericTextbox based on the configuration of a specific object. For example when WidgetA we display 10 price fields dynamically.  This user control works fine on any normal form.

Let's say we have a grid that provides a list of Widgets.  We are using a user control edit form for the widget.  The edit form also includes the custom Prices user control.  In ItemDataBound we call a method on the Prices user control to dynamically create the inputs based on which Widget we are editing.  This display and binding previous price entries works fine.

So we have
Grid
with WidgetEditControl
with Prices user control
On Grid ItemDataBound we call LoadPrices(id) method on the WidgetEditControl which calls another method on the Prices user control which dynamically adds the inputs needed

When attempting to pull in the data to save on the grid update command the viewstate and properties of the Prices user control are lost and we therefore can't pull them in to update.  Is there a way the prices user control can be added and/or bound so that when the update command on the grid fires the data from the prices user control is still available?

1 Answer, 1 is accepted

Sort by
0
Tsvetina
Telerik team
answered on 15 Aug 2012, 01:55 PM
Hi Jeff,

In order to be able to persist controls added in RadGrid upon postback, you should add them in ItemCreated, as it fires early enough and is called on each load of the page, while ItemDataBound fires only while the grid is binding.
Try loading the controls in ItemCreated and populate them in ItemDataBound, or event better, load all controls that might be needed in the Init phase of the user control and use ItemCreated/DataBound to only hide the unneeded ones and populate the rest.

Kind regards,
Tsvetina
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Grid
Asked by
Jeff Taynton
Top achievements
Rank 1
Answers by
Tsvetina
Telerik team
Share this question
or