0

我们正在使用 Ajax Control Toolkit 并在页面中放置了一个 UpdatePanel。页面布局由母版页控制。UpdatePanel 包含许多服务器端控件。启动 UpdatetePanel 的代码片段是:

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <Triggers>
        <asp:PostBackTrigger ControlID="btnSubmit" />
    </Triggers>

在 UpdatePanel 内,有一个 TabContainer 和许多服务器端控件。代码隐藏将其引用为:

        TabPanel TabPanel3 = new TabPanel();
    TabPanel3.HeaderText = "Manually Enter Allergy";
    TabContainer1.Controls.Add(TabPanel3);
    for (int k = 1; k <= 6; k++)
    {
        //CheckBox cb1 = new CheckBox();
        //cb1.ID = "cbOther" + k;
        TextBox txt = new TextBox();
        txt.ID = "txtAOther" + k;
        txt.CssClass = "finput";
        Literal lt = new Literal();
        lt.Text = "<br/>" + k + ".&nbsp;";
        //TabPanel3.Controls.Add(cb1);
        TabPanel3.Controls.Add(lt);
        TabPanel3.Controls.Add(txt);

    }

TabContainer 设置如下:

<asp:TabContainer ID="TabContainer1" runat="server" ActiveTabIndex="0">
</asp:TabContainer>

当我在本地运行此页面时,我收到以下错误:

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 t
the range of valid values.
Parameter name: value

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.
Parameter name: value]
AjaxControlToolkit.TabContainer.set_ActiveTabIndex(Int32 value) +255
AjaxControlToolkit.TabContainer.OnInit(EventArgs e) +121
System.Web.UI.Control.InitRecursive(Control namingContainer) +605
System.Web.UI.Control.InitRecursive(Control namingContainer) +323
System.Web.UI.Control.InitRecursive(Control namingContainer) +323
System.Web.UI.Control.InitRecursive(Control namingContainer) +323
System.Web.UI.Control.InitRecursive(Control namingContainer) +323
System.Web.UI.Control.InitRecursive(Control namingContainer) +323
System.Web.UI.Control.InitRecursive(Control namingContainer) +323
System.Web.UI.Control.InitRecursive(Control namingContainer) +323
System.Web.UI.Control.InitRecursive(Control namingContainer) +323
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean   
includeStagesAfterAsyncPoint) +2238

我很难理解为什么会抛出错误。最初的搜索不会产生明确的行动方案。任何人都可以就如何纠正错误提供一些指导吗?

4

1 回答 1

1

我猜在 ASPX 中你没有 TabPanels。这就是您收到该错误的原因,因为在您填充 PageLoad 中的选项卡之前,索引 0 无效。

去掉标记中的 ActiveTabIndex=0,然后在以编程方式添加选项卡后,在此处调用它:

TabContainer1.ActiveTabIndex=0;

于 2013-07-31T22:18:17.480 回答