Search code examples
asp.netvb.netviewstateresponse.redirecttabcontainer

Response.Redirect, keep tabcontainer on active tab


My VB.net tabcontainer needs to stay on the active tab when I have each submit going through the response.redirect.

How can I achieve this? I need that response.redirect there because it will show what has been added in the main tab container.

<asp:TabContainer runat="server" ActiveTabIndex="0" Height="200px" 
Width="175px" ScrollBars="Auto" EnableTheming="True" Font-
Underline="False" ID="TabContainer2" EnableViewState="False" 
Style="float:right; padding-left: 110px; margin-bottom: 340px;" 
OnActiveTabChanged="TabContainer1_ActiveTabChanged">


Protected Sub TabContainer1_ActiveTabChanged(ByVal sender As Object, 
ByVal e As EventArgs)
    ViewState("ActiveTabIdx") = TabContainer1.ActiveTabIndex
End Sub


Protected Sub SubmitCompanies_Click(ByVal sender As Object, ByVal e 
As System.EventArgs) Handles SubmitCompanies.Click
*****there is more code here but for this question, it's not necessary so it has been 
omitted*****
    Response.Redirect(Request.RawUrl)
    ViewState("ActiveTabIdx") = TabContainer1.ActiveTabIndex


Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) 
Handles Me.Load
ProductID.Value = Request.QueryString("id")
Page.Response.Cache.SetCacheability(HttpCacheability.NoCache)
If Not ViewState("ActiveTabIdx") Is Nothing Then
    TabContainer1.ActiveTabIndex = Convert.ToInt32(Session("ActiveTabIdx"))
End If
End Sub

Solution

  • ViewState won't work with Response.Redirect. With your current implementation, I would use QueryString or Session to store reference to the active tab.

    Response.Redirect(String.Format("{0}?tab={1}", Request.RawUrl, TabContainer1.ActiveTabIndex))