Looking at the documentation, there is no clear way that I see to delete/remove a tab. There are addTab, addCopy, moveTab, etc... but no deleteTab or removeTab or even closeTab.
I need to completely delete a tab. Has anyone seen a way to do this client-side?
Hi DK,
Thank you for a sample.
I could not reproduce exception on first cycle of add/remove, but it was raised when I repeated add/delete few times.The problem happens because contents of tabs have default values of IDs. The default values of templated-child-control IDs in naming-container (template) are generated by server and they appear like tmpl0, tmpl1, tmpl2, etc. When you removed tabs and keep old tabs saved (in session or similar), then there is a chance that autogenerated value of ID will be the same as ID of saved control. That situation triggers exception when server checks if controls are valid (to protect against problems with events view state actions).2 or more controls with same IDs are not exceptable.
I suggest to build logic, which ensures that child controls of each newly created tab have unique IDs. In that speceific sample, each tab has dynamic UserControlUrl. So, at the time of creation, an application may verify that the ID of that control is valid (explicitly defined) and if it is not, then set it to custom/unique value. The easiest way is to create a static counter, which will help build unique values for IDs.Check logic may include test for expected value/prefix or check for default "tmpl" prefix (last one can be dependant on specific version of server and can be unreliable).If application has mixed aspx-tabs, ContentUrl tabs, dynamic-not-UserControlUrl tabs, then "check" logic should be adjusted for that. Idea, is to ensure that all IDs of dynamic controls are unique.
Below is an example:
private object CreateWebTabDynamically(){ ... webTab.Tabs.Add(tab); this.FixID(tab); ...}protected void AddTab(object sender, EventArgs e){ ... webTab.Tabs.Add(tab); this.FixID(tab); ...}
private static int _id = 0;private void FixID(Control tab){ Control user = tab.HasControls() ? tab.Controls[0] : null; // here can be a better validation for dynamic user control if (user == null) return; string id = user.ID; if (string.IsNullOrEmpty(id) || id.IndexOf("tabID") < 0) //if (string.IsNullOrEmpty(id) || id.IndexOf("tmp") >= 0) user.ID = "tabID" + _id++;}
Hi V,
Your example worked good for me. But our system is very complex and it was very hard to reproduce this issue. But somehow I managed to do it. Enclosed is the zip file.
Here is how it works:
1) On launch you can see LoadTab button, on click new tabs are added with dynamic user control text box ( In my case there are gridview controls etc)
2) Create minimum 3 tabs
3) click on the close button of second tab (middle tab)
4) You can see the exception
Also i noticed that this JScript error does not occur if i change
private object CreateWebTabDynamically() { ArrayList tabs = QueryTabs;
for (int i = 0; i < tabs.Count; ++i) { QueryTab tab = (QueryTab)tabs[i];
//If i new up tab this JScript error does not occur. but i lose my user controls
tab.Text = tab.TabName; tab.Key = tab.TabName; tab.UserControlUrl = "Test1.ascx"; tab.Visible = true; tab.Enabled = true; webTab.Tabs.Add(tab); } return tabs;
}
Note: I could not enclose Images and AjaxControlToolkit.dll because of size restrictions
Thanks & Regards,
DK
Hi Dk,
I tried to reproduce that with following sample, but it worked without exceptions. When I load tabs, hide any of them and submit, then hidden tabs were removed. I could repeat hide/submit/load any number of times and never seen exception. Sure my sample is too simplistic. Maybe something else in your application causes that exception.If you have a simple sample which can be used to reproduce exception, then please zip aspx/aspx.cs files and attach it within OPTIONS tab.
aspx:
<ig:WebTab ID="WebTab1" runat="server" Width="500px" Height="300px"> <CloseButton Enabled="True" /> </ig:WebTab> <asp:Button ID="LoadTabs" runat="server" Text="LoadTabs" onclick="LoadTabs_Click" /> <asp:Button ID="SubmitForm" runat="server" Text="Submit" onclick="SubmitForm_Click" />
aspx.cs:
protected void LoadTabs_Click(object sender,EventArgs e){ for(int i = 0; i < 7; i++) { ContentTabItem tab = new ContentTabItem(); tab.Text = "Tab" + i; this.WebTab1.Tabs.Add(tab); }}protected void SubmitForm_Click(object sender,EventArgs e){ int count = this.WebTab1.Tabs.Count; while (count-- > 0) { ContentTabItem tab = this.WebTab1.Tabs[count]; if (tab.Hidden) this.WebTab1.Tabs.Remove(tab); }}
I have similar issue. I am creating tabs dynamically and have CLose tab functionality implemented same way you suggested. It is deleting tab from server but when it loads page it gives me JScript error and in ScriptResource.axd file. It looks like it is not resetting indexs on client side. it breaks at this._items[address][0][index].
Also one more thing to note that i am able to close tab without JScript error for first and last index successfully!
Appreciate your help!
Thanks,
Dk
Hi revbones,
The delete tab item on client (or any restructuring of tabs) is not supported because it will be not possible to maintain view states of old tab items. The only supported operation on client is to append (not insert) new tab item. In this situation a special flag is passed from client to server and view states of all existing/old tabs is preserved.The "move" action of tab item is not restructuring, but only changing a VisibleIndex property of a tab.
The restructuring of tabs (real move, insert, delete, etc.) is supported only on server. If application needs to delete tab item, then the easiest way it to hide it on client (and set a specific flag like "UNUSED" and on server find that tab item and remove it.
Below is example:
int count = this.WebTab1.Tabs.Count; while (count-- > 0) { Infragistics.Web.UI.LayoutControls.ContentTabItem tab = this.WebTab1.Tabs[count]; // use condition to remove //if (tab.Text == "Tab 2") //if (tab.Key == "UNSUSED") if (tab.Hidden) { this.WebTab1.Tabs.Remove(tab); } }