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

Manually closing WebUserControl Not working

4 Answers 48 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Shawn
Top achievements
Rank 1
Shawn asked on 01 May 2014, 02:02 PM
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

4 Answers, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 06 May 2014, 06:02 AM
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.

 
0
Shawn
Top achievements
Rank 1
answered on 07 May 2014, 03:44 PM
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?
0
Eyup
Telerik team
answered on 12 May 2014, 08:28 AM
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.

 
0
Shawn
Top achievements
Rank 1
answered on 14 May 2014, 07:05 PM
Eyup thanks for the help.  That did the trick.
Tags
General Discussions
Asked by
Shawn
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Shawn
Top achievements
Rank 1
Share this question
or