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, Revbones.
It's seems that the WebTab API don't have such client-side functionality. I suppose there is a reason for this so I will investigate it and will inform you.
Meanwhile I can suggest you workaround for this. You can hide the tabs on the client, those you want to delete, and on the server to check all the hidden tabs and delete them from the tabs collection.
var webTab = $find("<%=WebTab1.ClientID%>"),
tab = webTab.getTabAt(0);
tab.set_hidden(true);
I hope this will help you.
Thanks,Nikolay
Unfortunately hiding tabs won't work for me. I'm loading data via client side templates and feel fairly certain that after a while of creating and hiding tabs that I'll start to run into trouble.
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); }}
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,
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,
I added this FixID method in the sample application I had send to you and it was giving still same JScript error. I happens if you open three tab and close the center one i.e., Tab0 Tab1 and Tab2. If you try to close Tab1 you can see that JScript.
Thanks for immediate response
Dk
I could not reproduce JScript error on the first attempt to remove 2nd tab, but only after repeating add/remove actions few times. Last time I tested your codes with asp:ScriptManager. Today I added reference to AjaxControlToolkit and replaced ScriptManager with asp:ToolkitScriptManger.
Both cases worked exactly same way and exception was raised in MicrosoftAjaxWebForms.debug.js.
Under ScriptManager it was at the end of
function Sys$WebForms$PageRequestManager$_endPostBack(error, executor, data) {...}
and in case of ToolkitScriptManager it was at the end of a similar function
_endPostBack: function PageRequestManager$_endPostBack(error, executor, data) {...}
I tested sample within a website of VisualStudio2008. AjaxControlToolkit.dll: 11/16/2011, File Version: 3.5.51116.0.
Maybe there is something else is different in our samples, or there are different versions of AjaxControlToolkit.
Ok I got it working with the latest Service Release of Infragistics35.Web.v11.2 version Version=11.2.20112.2159,
and also Infragistics35.Web.v12.1 with latest service release Version=12.1.20121.2048.
Thanks,
Hi VK,
I was on vacation and could not reply you earlier. Actually I tried my sample application with Infragistics35.Web.v12.1, Version=12.1.20121.1005 and I am getting exactly same behaviour.
Appreciate your help!
I built debug dll for version 11.2.20112.1019 and reproduced exception, which you referred to.
Please, get latest service release for NetAdvantage.
We have license for Infragistic dll 11.2 dll and its version is 11.2.20112.1019.
About AjaxControlToolkit , I was using old version earlier and was facing similar issue. Upgrading to latest version did not help at all.
Thanks for prompt responses,
I cannot give my personal email, maybe there are some other options to down load large attachement. I can consult developer support about that.
I assume that you have latest version of 11.2 dll, which is 11.2.20112.2159 or 11.2.20112.2141. Those versions should be ok. If you have earlier version, then please give me its exact version. (You may look at File version within Details of dll Properties).I could try to find its date in tfs history, gets all files for that date and build debug dll from them. Though, I would like to avoid similar.That is possible that there are other changes in codes of WebTab (besides InstantiateTemplates within OnInit), which make difference for your application.
The best choice is to use the most recent available service release.
To exclude possible issue with version of AjaxControlToolkit, you may replace it in your sample by ScriptManager and check if it makes any difference.