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

How to close EditForm (UserControl) after update or cancel

10 Answers 1352 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Walter
Top achievements
Rank 1
Walter asked on 26 Feb 2013, 05:40 PM
After spending hours looking through documentation and the forums I can't figure out why my edit form doesn't close.
In my RadGrid I include an EditFormSettings tag, specifying EditFormType="WebUserControl" and the name of the control. Nested in this tag I have an EditColumn tag.
In the RadGrid Columns collection I have a GridEditCommandColumn tag.
The User Control I'm using for editing has a DataItem public property which is used to populate the editing controls (textboxes and comboboxes).
In the User Control I have two buttons. The "Save" button has OnClick="BtnSaveClick" and CommandName="Update". The BtnSaveClick method in the user control's code-behind updates the database using Entity Framework. The "Cancel" button has CommandName="Cancel".
I am able to edit and successfully update records.
The problem is that after updating the database, or if the user clicks the Cancel button, the edit form remains visible.
How do I cause the edit form to close after an update or after clicking the Cancel button?
Thanks in advance for your help. This is driving me nuts.

Here is an excerpt from the page:
<MasterTableView DataKeyNames="AccessRequestId, ContractorId" AllowAutomaticUpdates="False">
  <EditFormSettings UserControlName="~/UserControls/AccessRequestEditForm.ascx" EditFormType="WebUserControl" >
    <EditColumn UniqueName="EditCommandColumn1" ></EditColumn>
  </EditFormSettings>
<Columns>
  <telerik:GridEditCommandColumn UniqueName="EditCommandColumn">
  </telerik:GridEditCommandColumn>
  ...more columns...
</Columns>
</MasterTableView>

Here are the buttons in my user control:

<div runat="server" id="divButtons">
      <asp:Button runat="server" ID="btnSave" Text="Save" OnClick="BtnSaveClick" CommandName="Update" CausesValidation="true" />
      <asp:Button runat="server" ID="btnCancel" Text="Cancel" OnClick="BtnCancelClick" CommandName="Cancel" CausesValidation="false"/>
   </div>

10 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 27 Feb 2013, 05:50 AM
Hi,

Try setting CausesValidation as false for the Button.
aspx:
<asp:Button runat="server" ID="btnSave" Text="Save" OnClick="BtnSaveClick" CommandName="Update" CausesValidation="false" />

Thanks,
Princy
0
Walter
Top achievements
Rank 1
answered on 27 Feb 2013, 01:50 PM
Thanks, but no good. First of all, I need the Save button to cause validation. Secondly, changing it to not cause validation made no difference - the edit form still does not close. Thirdly, the Cancel button has the same problem.

Still open to any suggestions!!
0
Radoslav
Telerik team
answered on 01 Mar 2013, 08:39 AM
Hi Michael,

Could you please try removing the click event handlers of the buttons and left only the command names like is shown in the following example and let me know if the issues still persists:
http://demos.telerik.com/aspnet-ajax/grid/examples/dataediting/usercontroleditform/defaultcs.aspx

Looking forward for your reply.

Regards,
Radoslav
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.
0
J
Top achievements
Rank 1
answered on 01 Mar 2013, 01:42 PM
Here's how I got mine to close every time:

protected void grdAthletes_UpdateCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
{
    try
    {
        //Close out any open edit items and update the data displayed in the grid
        grdAthletes.MasterTableView.ClearEditItems();
        grdAthletes.Rebind();
    }
    catch (Exception ex)
    {
        System.Diagnostics.Debug.Print("Error: " + ex.Message);
    }
}
0
Andrew
Top achievements
Rank 1
answered on 06 Jun 2014, 03:07 AM
Kudos to you sir 1+ years later :)
0
Doug
Top achievements
Rank 2
answered on 23 Jun 2015, 02:07 PM
Thank you J, this fixed my issue 2 years later :-)
0
Liby George
Top achievements
Rank 1
answered on 03 Nov 2015, 05:47 PM
Thank you J for your answer!. You saved me a lot of time.
0
Madhu
Top achievements
Rank 1
answered on 19 Aug 2016, 06:18 AM
Kudos to you sir 4 years later 
0
CHRIS
Top achievements
Rank 1
answered on 30 Sep 2018, 03:40 AM
Kudos to you sir 6  years later     - excellent force the exit
0
CB
Top achievements
Rank 2
answered on 24 Mar 2019, 01:42 AM

Kudos to you sir 6 years 3 weeks and 3 days later :) Thank you this was really annoying me!

Telerik I think this should be put in your documentation or resolved in a future build - thank you.

Tags
Grid
Asked by
Walter
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Walter
Top achievements
Rank 1
Radoslav
Telerik team
J
Top achievements
Rank 1
Andrew
Top achievements
Rank 1
Doug
Top achievements
Rank 2
Liby George
Top achievements
Rank 1
Madhu
Top achievements
Rank 1
CHRIS
Top achievements
Rank 1
CB
Top achievements
Rank 2
Share this question
or