ASP.NET Maintaining ActiveTabIndex on Postback wit

2019-08-19 13:03发布

This probably has been asked many times before but I was wondering how to maintain the ActiveTabIndex of an AjaxControlToolKit TabContainer.

The only way I can think of achieving such a thing is to store the ActiveTabIndex in the session and checking for this on postback. Are there any other solutions to solve this problem?

3条回答
Juvenile、少年°
2楼-- · 2019-08-19 13:53

Most likely this answers your question. Such things belong into the ViewState of the Page when their not already saved there.

EDIT: On the other hand: i've tested it and my ActiveTabIndex maintains on (asynchronous) postback.

查看更多
倾城 Initia
3楼-- · 2019-08-19 13:56

No need to mess with Session on this, Malachi.

Just drop this in your "ActiveTabChanged" event handler (assuming you are using C#):

int iTabIndex = int.Parse(Request.Params["__EVENTARGUMENT"].Split(':')[1]);

Then perform whatever logic you need based on the value of "iTabIndex".

查看更多
孤傲高冷的网名
4楼-- · 2019-08-19 13:59

you need to add ActiveTabChanged event for tab container and you can keep active tab index in view state, and on page load just check if it is not null then set it as Active tab index.

 protected void TabContainer1_ActiveTabChanged(object sender, EventArgs e)
    {
        ViewState["ActiveTabIndex"] = TabContainer1.ActiveTabIndex;

    }

PageOnLoad Event code

if (!(ViewState["ActiveTabIndex"] == null) )
        {            
               TabContainer1.ActiveTabIndex = (int)ViewState["ActiveTabIndex"];          

        }

Make sure to add following attributes in TabContainer tag

AutoPostBack="true" OnActiveTabChanged="TabContainer1_ActiveTabChanged"
查看更多
登录 后发表回答