Hi Joel,
I see what you meant now. Our TabStrip can store all the tabs in the view state. So a combined solution using both session and view state is the easiest. The only issue for this, as you have noticed, is that it only works with post backs.
It's fairly easy when the page posts back. I can think of the following logic that might work for you:
Page_Load:
Code: C#
//Load from session only when the page is a fresh get.
//When the page is posted back, ignore data in the session,
//The TabStrip will automatically load from view state
if (!Page.IsPostBack)
{
this.navigationTabStrip.DataSource = AppContext.GetCurrentTabs();
this.navigationTabStrip.DataBind();
}
The key at here is that, while you use both Session (which contains the last tabset on the server side) and ViewState (which contains the "active" tabset on the client side), ViewState takes priority over Session. So in the case you have two browser tabs, one with A, B, C and the other have D, E, F, G, and then user click A, your ViewState has A, B, C, even though session has D, E, F, G. Because ViewState takes priority over Session, your app continues based on A, B, C, not D, E, F, G.
In order to have the TabStrip to post back the page for you, you will need to:
1. Clear the TabItem's NavigateUrl. When you have NavigateUrl set, the TabStrip does a straight window.open on the client side and the page won't be posted back to the server;
2. Set the TabStrip's RaisesServerEvent to true. Without setting this property, the TabStrip will not post back to the server either;
When this two conditions are meet, the TabStrip posts back to the server and raises ItemClick server side event when a tab is clicked. Inside your ItemClick handler, you may update your session data to have the latest "app tab list" based on the user selection.
You do not need to manually select the new Tab in this case because everything is automatically loaded from view state. If you do need to switch to some other tab, you can do so by:
Code: C#
//Note usually you do not need to do this because everything
//is automatically loaded from view state
navigationTabStrip.SelectedIndex = new_index;
As noted above, this only works when ViewState data exists, in another word, only when the page posts back. When the page is a fresh get, no ViewState data is available. Hidden field won't work either because that too rely on post back. In that case it will completely fall back to rely on session data.
Storing a "version number" along with the session can address non-postback scenario. However that would require you to put the version number in the Url (hidden field won't work), which in my opinion, would be much more complicated to implement than just let the page to post back and then redirect. Comparing with post back, using "version number" may have a slight performance advantage in term of bandwidth, but it does have a performance disadvantage on server resources because it needs to store more data on the server side.
In order to have the TabStrip to postback and then redirect, you can store the target Url for a TabItem in the item's Value property (instead of NavigateUrl). Then call Response.Redirect in your server side ItemClick event handler:
Code: C#
private void navigationTabStrip_ItemClick(
object sender, EO.Web.NavigationItemEventArgs e)
{
//Do other work such as update your session data.....
......
Response.Redirect(e.TabItem.Value);
}
Hope this helps.
Thanks