Manually closing WebUserControl Not working

5 posts, 0 answers
  1. Shawn
    Shawn avatar
    14 posts
    Member since:
    Dec 2012

    Posted 01 May 2014 Link to this post

    So I have the following:
    <EditFormSettings UserControlName="UserControls/JobDetail.ascx" EditFormType="WebUserControl">    

    Then within the user control I have the following:

    <telerik:GridTemplateColumn>
        <ItemTemplate>
            <asp:LinkButton ID="lnkUpdate" runat="server" Text="Update" CommandName="UpdateAction" CausesValidation="false" CommandArgument='<%# Eval("ActionId")%>' />
        </ItemTemplate>
    </telerik:GridTemplateColumn>      

    I've tried the following:

    AllowAutomaticUpdates="false"

    I've tried the following in my code behind to close the user control manually.

    e.Canceled = true;
    RadGrid2.MasterTableView.ClearEditItems();
    RadGrid2.MasterTableView.ClearChildEditItems();
    RadGrid2.MasterTableView.ClearSelectedItems();
    RadGrid2.Rebind();

    Any thoughts on how close the user control manually from code behind?

    Thanks,

    Shawn
  2. Eyup
    Admin
    Eyup avatar
    3007 posts

    Posted 06 May 2014 Link to this post

    Hello Shawn,

    Generally, the edit form should close following an Update command. Assuming that you have a second grid in the EditForm of the main grid, can you please verify that RadGrid2 is the ID of main grid?

    In addition, you can also try to fire a Cancel command using the e.Item GridEditableItem:
    http://www.telerik.com/help/aspnet-ajax/grid-fire-command-event-from-code.html

    Looking forward to your reply.

    Regards,
    Eyup
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. Shawn
    Shawn avatar
    14 posts
    Member since:
    Dec 2012

    Posted 07 May 2014 in reply to Eyup Link to this post

    Thanks Eyup for the reply.  RadGrid1 is the main grid and RadGrid2 is the WebUserControl's grid name.  Everything works find if I have a Cancel Button.  See below.  This is outside the RadGrid.  

    <asp:Button ID="btnCancel" Text="Cancel Updates" runat="server" CausesValidation="False" CommandName="Cancel"></asp:Button>

    This closes the form every time.  I need to close the grid myself on an update or edit.  

    I tried your suggestion above and I'm still in the same boat.

    e.Item.FireCommandEvent("Cancel", string.Empty);

    It basically just comes back into my RadGrid2_ItemCommand method and doesn't close the grid.

    Any other thoughts?
  4. Eyup
    Admin
    Eyup avatar
    3007 posts

    Posted 12 May 2014 Link to this post

    Hello Shawn,

    From the provided description I can say that this behavior is expected. As you've mentioned, RadGrid1 is the main grid and RadGrid2 is the grid placed in the JobDetail.ascx WebUserControl. Now, if I did understand you correctly, you want to close the RadGrid1's Edit Form, which is the User Control, on RadGrid2's Update or  PerformInsert command.

    To do that, you can try to call the ClearEditItems method to the main grid and rebind it afterwards: RadGrid1.MasterTableView.ClearEditItems();


    Alternatively, you can use the FireCommandEvent as suggested in my previous post, however, since the ItemCommand event handler is initiated for RadGrid2, the e.Item control returns the item of RadGrid2. Instead, you have to get the reference of the item of RadGrid1:
    protected void RadGrid2_ItemCommand(object sender, GridCommandEventArgs e)
    {
        if (e.CommandName == RadGrid.UpdateCommandName
         || e.CommandName == RadGrid.PerformInsertCommandName)
        {
            GridEditableItem mainItem = e.Item.OwnerTableView.OwnerGrid.NamingContainer.NamingContainer
                as GridEditableItem;
            mainItem.FireCommandEvent("Cancel", "");
        }
    }

    Hope this helps.

    Regards,
    Eyup
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  5. Shawn
    Shawn avatar
    14 posts
    Member since:
    Dec 2012

    Posted 14 May 2014 in reply to Eyup Link to this post

    Eyup thanks for the help.  That did the trick.
Back to Top