How to close EditForm (UserControl) after update or cancel

9 posts, 0 answers
  1. Walter
    Walter avatar
    6 posts
    Member since:
    Jul 2011

    Posted 26 Feb 2013 Link to this post

    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>

  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 26 Feb 2013 Link to this post

    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
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Walter
    Walter avatar
    6 posts
    Member since:
    Jul 2011

    Posted 27 Feb 2013 Link to this post

    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!!
  5. Radoslav
    Admin
    Radoslav avatar
    1564 posts

    Posted 01 Mar 2013 Link to this post

    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.
  6. J
    J avatar
    103 posts
    Member since:
    Feb 2013

    Posted 01 Mar 2013 Link to this post

    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);
        }
    }
  7. Andrew
    Andrew avatar
    6 posts
    Member since:
    Jul 2012

    Posted 05 Jun 2014 in reply to J Link to this post

    Kudos to you sir 1+ years later :)
  8. Doug
    Doug avatar
    14 posts
    Member since:
    Apr 2013

    Posted 23 Jun 2015 Link to this post

    Thank you J, this fixed my issue 2 years later :-)
  9. Liby George
    Liby George avatar
    4 posts
    Member since:
    Jan 2014

    Posted 03 Nov 2015 in reply to J Link to this post

    Thank you J for your answer!. You saved me a lot of time.
  10. Madhu
    Madhu avatar
    2 posts
    Member since:
    Oct 2012

    Posted 19 Aug in reply to J Link to this post

    Kudos to you sir 4 years later 
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017