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

RadGrid ItemCreated and User Controls...

1 Answer 305 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Pete
Top achievements
Rank 1
Pete asked on 27 Apr 2011, 03:55 PM
Hi,
Maybe someone out there could help me out here.

I have a Page that binds data to a grid that then (depending on the data within that row) adds a usercontrol to a cell within that row.  The data is bound only once to the grid and I have placed the logic to add the usercontrols to the ItemCreated event for the grid (so that everytime the grid causes a Postback the usercontrols are recreated).  Now there is a need for functionality to allow the user to add a new instance of the user control (of the same type) to the cell.

I have tried the following:

  1. I have used the serverclick event of a button to add the new control to the grid - however, as the control is added after LoadViewState any user entered data to the control is not maintained by Viewstate.  At least on the first passthrough of a Page lifecycle the data is not maintained however, if the Item created event knows that an extra user control is required for a given row then any subsequent postbacks would allow the data entered to be mainteained by Viewstate  Ie.
            -- On first load --
            PAGELOAD (Bind grid)
                -> ONDATABOUND
                -> ONITEMCREATED (adds user controls to specific cell in RadGrid)
            -- On server click to add new control (Causing Postback) --
            ONITEMCREATED (adds user controls to specific cell in RadGrid)
                -> PAGELOAD (Grid not bound)
                -> BUTTONCLICK EVENT (add new usercontrol to correct row)
                (Data entered to added control)
            -- On Second server click to add new control (Causing Postback) --
            ONITEMCREATED (adds user controls to specific cell in RadGrid adding the extra User control for the effected row)
                -> PAGELOAD (Grid not bound)
                (Data entered on added control not set)
                -> BUTTONCLICK EVENT (add new usercontrol to correct row)
                (Data entered to the first added control)
                (Data entered into the newly added control)
            -- On Third server click to add new control (Causing Postback) --
            ONITEMCREATED (adds user controls to specific cell in RadGrid adding the extra 2 User control for the effected rows)
                -> PAGELOAD (Grid not bound)
                (Data entered on first control control set - data entered into second not set)
                -> BUTTONCLICK EVENT (add new usercontrol to correct row)

    I have tried using a variety of different methods to force a manual postback following the Buttonclick event to ensure a new 'full' page lifecycle occurs (after the serverclick event) so that Viewstate saves the user input but this results in a very messy clientside and serverside code...
  2. I added a clientside onclick event to the serverclick button that sets a hidden textbox with data that could be used by the ITEMCREATED event to build the correct usercontrols in the grid.  However, the hidden textbox is always empty when the Itemcreated event is fired as the viewstate has not been loaded at that time following the postback.  I could not think of another way to pass the data to allow it to be available to the Itemcreated method (other than the use of Cookies which would be set by a Javascript function kicked off by the onclick event from the serverclick button... and then this could be consumed by the ItemCreated method)
  3. The final option which does work though performance is poor.. is to Response.Redirect to the page following the button serverclick event... I save required data within the database but the Itemcreated method builds and adds the usercontrols at the right time...

Are there any other ways that people out there could think of to get this to work... Biggest problem is that the ItemCreated event gets fired before PageLoad on Postback.  I think I will proceed with the Cookie method as it allows for performance but there would be the problem that people with Cookies disabled would not be able to use the system... well they could use it...  but the Viewstate not storing entered userdata on dynamically created usercontrols on first appearance would still rear it's ugly head...

Any smart people out there with any other ideas???

1 Answer, 1 is accepted

Sort by
0
Iana Tsolova
Telerik team
answered on 02 May 2011, 08:38 AM
Hi Pete,

Basically, the you should not have any problems if you add the user control on button click server-side event handler and on subsequent postbacks re-create the newly added control on ItemCreated.
Another approach you can try is on client click to save the desired information in a HiddenField instead of hidden textbox. thus you should be able to get the hidden field value on ItemCreated through the Page.Request.Form collection.

Check it out and let me know how it goes.

Greetings,
Iana
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

Tags
Grid
Asked by
Pete
Top achievements
Rank 1
Answers by
Iana Tsolova
Telerik team
Share this question
or