【问题标题】:Creating TABCONTAINER with ajax dynamically ASP.NET使用 ajax 动态创建 TABCONTAINER ASP.NET
【发布时间】:2014-01-24 12:24:07
【问题描述】:

在标签容器中,我希望显示包含不同用户控件的各种标签。 我需要通过代码将用户控件分配给选项卡,而不是像通常在标签中那样分配用户控件,例如:

<ajaxToolkit:TabPanel runat="server" HeaderText="NOMBRE" ID="TabPanel1"  Enabled ="true" >
    <ContentTemplate>

    </ContentTemplate>
</ajaxToolkit:TabPanel>

对于我需要的,这不起作用。

所以这是我将标签分配给用户控件的代码,代码如下:

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
         Control ctrlNombre = LoadControl("~/UserCtrl/Nombre.ascx"); //user control
         TabPanel1.Controls.Add(ctrlNombre);  //add user control to tabpanel     
     }
 }

而“onactivetabchanged”事件我根据哪个选项卡处于活动状态创建了一个菜单,它将加载控件,代码如下:

protected void TabContainer1_ActiveTabChanged(object sender, EventArgs e)
{
    switch(TabContainer1.ActiveTabIndex)
    {
         case 0:
             Control ctrl1 = LoadControl("~/UserCtrl/userControl1.ascx");
             TabPanel1.Controls.Add(ctrlNombre);
             break;
          case 1:
             Control ctrl2 = LoadControl("~/UserCtrl/ userControl2.ascx");
            TabPanel1.Controls.Add(ctrlApPaterno);

    }
 }

但是,这确实有效,当我从某个用户控件单击某个按钮时会出现问题,这会像往常一样将完整的帖子发回服务器,但是这个帖子会导致之前加载的用户控件消失。我能做些什么来解决这个问题?我真的希望有人能帮助我解决这个问题,我将非常感激。

这是我单击按钮时发生的情况的图像:

非常感谢你们,希望有人能帮我解决这个问题。

【问题讨论】:

    标签: c# asp.net tabcontrol tabpanel tabcontainer


    【解决方案1】:

    当回发发生在 Page_init 中时,您可能需要重新创建标签面板,因为标签面板在回发之前不存在...

    所以在 Page_init 中你应该调用一个函数来创建默认选项卡集合,然后在页面上你可以添加一个新的选项卡面板到集合中。

    protected void Page_Init(object sender, EventArgs e)
    {
         Control ctrlNombre = LoadControl("~/UserCtrl/Nombre.ascx"); //user control
         TabPanel1.Controls.Add(ctrlNombre);  //add user control to tabpanel   
    }
    

    参考:

    http://dorababu-meka.blogspot.com/2012/12/create-dynamical-ajax-tab-and-filling.html http://www.c-sharpcorner.com/uploadfile/Ravish001/create-dynamic-tabs-using-ajax-tab-container-add-controls-read-them-dynamically/

    希望这是有道理的。

    【讨论】:

    • 我会尝试您提供的任一链接,如果它帮助我解决了这个问题,我会更新您,感谢您编辑我的帖子,非常感谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-22
    • 1970-01-01
    • 2012-08-13
    • 1970-01-01
    • 1970-01-01
    • 2023-04-05
    相关资源
    最近更新 更多