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

Trouble closing dynamically added tabs from ascx

1 Answer 52 Views
TabStrip
This is a migrated thread and some comments may be shown as answers.
Tim
Top achievements
Rank 1
Tim asked on 31 Aug 2011, 08:41 PM
I have a tab strip on the aspx.  Code behind on that page allows me to open items from a grid that's on one of those tabs.  As the user opens items, the first time an "Open Tests" tab gets dynamically added to the tab strip and a child tab gets added to that new tab for the item they opened.  Additional opened tests get their own child tabs.  I'm allowing up to 5 to keep resources under control.  Each of these tabs gets its own page view in the multipage and the content is set to an ascx so that each new child tab has the same controls, just with the data for the record they opened.

On that ascx is a "Close" button.  Click event on this button is this:

protected void ButtonClose_Click(object sender, EventArgs e)
{
    RadTabStrip rts = (RadTabStrip)this.Parent.FindControl("rtsDQEApplication");
    RadTab currentTab = rts.InnermostSelectedTab;
 
    if (currentTab != null)
    {
        IRadTabContainer owner = currentTab.Owner;
        owner.Tabs.Remove(currentTab);
        RadMultiPage rmp = (RadMultiPage)this.Parent.FindControl("rmpDQEApplication");
        rmp.PageViews.RemoveAt(rmp.SelectedIndex);
    }
}

Thing is, you have to click the "Close" button twice to remove the tab.  I put a breakpoint on the first line so that I could debug this code and what happens is, the user clicks the close button on an open child tab and it jumps to the code and I can F11 all the way through.  Everything goes fine, but when it returns to the form, the tab is still there.  Click the button again and it removes without going back to the breakpoint again.

If you do anything else in between, like click "Close" then change to a different tab and come back, it still wants you to click it twice.

Something's going on where the tabstrip itself isn't refreshing until the second click of the button; some sort of "timing of the postbacks" issue.  Any ideas?

1 Answer, 1 is accepted

Sort by
0
Dimitar Terziev
Telerik team
answered on 06 Sep 2011, 11:40 AM
Hello Tim,

In order to troubleshoot this issue, please try to change your code as following:
protected void ButtonClose_Click(object sender, EventArgs e)
{
    RadTabStrip rts = (RadTabStrip)this.Parent.FindControl("rtsDQEApplication");
    RadTab currentTab = rts.InnermostSelectedTab;
 
    if (currentTab != null)
    {
        RadTab owner = currentTab.Parent as RadTab;
        owner.Tabs.Remove(currentTab);
        RadMultiPage rmp = (RadMultiPage)this.Parent.FindControl("rmpDQEApplication");
        rmp.PageViews.RemoveAt(rmp.SelectedIndex);
    }
}

In case you still experience the same issue after implementing the above suggested approach, please open a support ticket and provide us a runnable sample project so we could examine the issue locally.

Regards,
Dimitar Terziev
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

Tags
TabStrip
Asked by
Tim
Top achievements
Rank 1
Answers by
Dimitar Terziev
Telerik team
Share this question
or