前台:
<cc1:TabContainer ID="tabs" runat="server" ActiveTabIndex="0" Height="200px" Width="500px" enableTabScroll="True" >
<cc1:TabPanel runat="server" HeaderText="首页" closable="False" ID="TabPanel1" TabIndex="0">
<HeaderTemplate>首页</HeaderTemplate>
<ContentTemplate></ContentTemplate>
</cc1:TabPanel>
<cc1:TabPanel runat="server" HeaderText="我的工作台2" closable="False" ID="TabPanel2" TabIndex="1">
<HeaderTemplate>我的工作台2</HeaderTemplate>
<ContentTemplate></ContentTemplate>
</cc1:TabPanel>
</cc1:TabContainer>
还有一个“添加”按钮
后台:
protected void Page_Load(object sender, EventArgs e) {
if (!IsPostBack) {
ViewState["TabIndexCount"] = 1;
}
}
//添加按钮事件
protected void LinkButton1_Click(object sender, EventArgs e) { ViewState["TabIndexCount"] = Convert.ToInt32(ViewState["TabIndexCount"].ToString()) + 1;
TabPanel tab = new TabPanel();
tab.HeaderText = "NewTab";
tab.TabIndex = (short)(Convert.ToInt32(ViewState["TabIndexCount"]));
tab.ID = "TabPanel" + (Convert.ToInt32(ViewState["TabIndexCount"]) + 1).ToString();
this.tabs.Tabs.Add(tab);
}
点击添加按钮创建新的TABPANEL的时候,第一次是成功的,但是第二次点击按钮,就报错:
指定的参数已超出有效值范围?
请教下如何解决?原因?