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

[Solved] radgrid usercontrol popup edit form lost on postback

1 Answer 362 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Sylvain
Top achievements
Rank 1
Sylvain asked on 13 Nov 2009, 03:19 PM
Hello,
 
I've setup my radgrid to open a usercontrol in a popup when double clicking on a row for editing. If I edit the row using the control and save or if I cancel, all is fine. The save is being handled by an UpdateCommand event that is in my main page, the same one where the grid exist.

The UpdateCommand event function properly extracts the value, and updates the row within a beginedit/endedit pair. Right after the endedit, I call AcceptChanges on my dataset (the datasource is the business layer of a dataset that is bound using the needdatasource event).

The call to AcceptChanges triggers the grid Rowchanging event within which (on DataRowAction.Change) I call the update method of my business layer. My business layers validates the data, making sure it is ok to be updated in the database and updates the row in the database using dataadapter methods if all is ok.

This works great.

... Except when the business layer validation finds that the row is not ok. The way I have it setup is that it generates an exception with the error message (with throw new exception("error message")). This eventually goes up to the UpdateCommand function which traps it and creates a new label control to display the message at the top of the editform usercontrol and sets e.canceled to true. The label displays properly. Here is how I do it:

 

            catch (Exception ex)  
            {  
                changedRows[0].CancelEdit();  
                Label lc = new Label();  
                lc.Text="ERROR: "+ex.Message;  
                lc.ForeColor=Color.Red;  
                userControl.Controls.AddAt(0,lc);  
                e.Canceled=true;  
                e.Item.Edit = true;  
            }  
 

The problem: After this takes place, it seems that while the popup remains on the screen, the page has lost track of it. If I click my save button again then the updatecommand event is never called and the popup simply disappears. Other events defined in the user control also no longer take place.

It is probably something with radgrid not saving the usercontrol to viewstate. Any ideas how I can fix that?

-=-
On a somewhat related subject, while I'd very much like to find a solution to the above, I am also considering moving the editform to its own page. This is because when I double click on a row to open up the popup edit box with user control, radgrid implements that by a full postback that resends the whole grid (and page), this time including the popup right in the middle of the grid's generated html. The same thing takes place when I hit save or cancel in the edit popup. It has been suggested here that I should look at client-side databinding and editing but I'd like to avoid doing that. For now I see two options: 1) double-clicking on rows openup a new browser window with a new page or 2) I put my editform below the grid and load it and make it visible and jump to it when I double click on a row and put all of that in a radpanel so that this can be handled by an ajax request instead of a full post back.

Any thoughts on this and links to examples?

Regards,
 
Sylvain

 

1 Answer, 1 is accepted

Sort by
0
Iana Tsolova
Telerik team
answered on 18 Nov 2009, 03:20 PM
Hi Sylvain,

Could you please try modifying the catch block as below and let me know if it makes any difference:

catch (Exception ex)   
            {   
                changedRows[0].CancelEdit();                   
                e.Canceled=true;   
            }   

Regarding your othe questions: You can wrap the grid into a RadAjaxPanel or ajaxify it with RadAjaxManager and use the current popup edit form. Thus upon edit/update/cancel a callback will be performed. However, if you still prefer using a separate page for editing, I suggest that you check the window editing demo here.

Kind regards,
Iana
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Grid
Asked by
Sylvain
Top achievements
Rank 1
Answers by
Iana Tsolova
Telerik team
Share this question
or