When I try to create a new tab for a TabPanel it throws the following error:
Specified argument was out of the range of valid values.
Parameter name: index
Description: An
unhandled exception occurred during the execution of the current web
request. Please review the stack trace for more information about the
error and where it originated in the code.
Exception Details: System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values.Parameter name: index
Source Error:
An unhandled exception was generated during the execution of the
current web request. Information regarding the origin and location of
the exception can be identified using the exception stack trace below.
|
Stack Trace:
[ArgumentOutOfRangeException: Specified argument was out of the range of valid values. |
System.Web.UI.ControlCollection.get_Item(Int32 index) +2057550 |
AjaxControlToolkit.TabPanelCollection.get_Item(Int32 index) +29 |
AjaxControlToolkit.TabContainer.LoadClientState(String clientState) +216 |
AjaxControlToolkit.ScriptControlBase.LoadPostData(String postDataKey, NameValueCollection postCollection) +74 |
AjaxControlToolkit.TabContainer.LoadPostData(String postDataKey, NameValueCollection postCollection) +32 |
AjaxControlToolkit.ScriptControlBase.System.Web.UI.IPostBackDataHandler.LoadPostData(String postDataKey, NameValueCollection postCollection) +11 |
System.Web.UI.Page.ProcessPostData(NameValueCollection postData, Boolean fBeforeLoad) +718 |
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3776 |
The problem seems to be that you can only create tabs dynamically once on a user event such as a button click. However you can create as many as you want at the initial attempt it is the subsequent inserts that fail.
EXAMPLE
XHTML markup:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="testpage.aspx.cs" Inherits="testpage" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager" runat="server" />
Try this example, you can only create tabs dynamically once on a user event such as a button click, yet you can create as many as you want in one shot.<br />
Try this page now. Then uncomment the code in the Page_Load event and try again.<br />
Number of Tabs to Create<asp:TextBox ID="txtNumberOfTabs" Text="5" runat="server" />
<asp:Button ID="btnAddTab" Text="Add Tab(s)" OnClick="btnAddTab_Click" runat="server" />
<ajaxToolkit:TabContainer ID="tabContainer" runat="server">
<ajaxToolkit:TabPanel runat="server" HeaderText="The First Tab">
<ContentTemplate>
</ContentTemplate>
</ajaxToolkit:TabPanel>
</ajaxToolkit:TabContainer>
</div>
</form>
</body>
</html>
Code behind:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class testpage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//for (int i = 0; i < Int32.Parse(txtNumberOfTabs.Text.ToString()); i++)
//{
// AjaxControlToolkit.TabPanel thePanel = new AjaxControlToolkit.TabPanel();
// thePanel.HeaderText = "tab" + (tabContainer.Tabs.Count);
// thePanel.ID = "tab" + (tabContainer.Tabs.Count);
// tabContainer.Tabs.Add(thePanel);
//}
}
protected void btnAddTab_Click(Object sender, EventArgs e)
{
for (int i = 0; i < Int32.Parse(txtNumberOfTabs.Text.ToString()); i++)
{
AjaxControlToolkit.TabPanel thePanel = new AjaxControlToolkit.TabPanel();
thePanel.HeaderText = "tab" + (tabContainer.Tabs.Count);
thePanel.ID = "tab" + (tabContainer.Tabs.Count);
tabContainer.Tabs.Add(thePanel);
}
}
}
Configuration:
Microsoft .NET Framework Version:2.0.50727.42; ASP.NET Version:2.0.50727.42
AJAX.net: 1.0.61025.0
AJAXToolkit 1.0.10201.0