Search code examples
jquery-tabs

Retain jquery tabs after redirect


I am having jquery tabs inside the parent menus, I want to retain the opened tabs after the page redirect.

HttpContext.Current.Response.Redirect("~/HRMS/PayrollHome.aspx", false);

Solution

  • You could always store when tabs are opened and closed in the session. Then when the page is visited again you can check if each tab is listed as being open in the session and if it is re-open it.

    EDIT

    Its difficult to give you entire code snippets that answer your problem completely because I haven't got access to your code base. But it would be something like this.

    <ul id="tabs">
      <li onclick="$.get("SaveTab.ashx?tab=1");">Tab 1</li>
      <li onclick="$.get("SaveTab.ashx?tab=2");">Tab 2</li>
    </ul>
    

    Then in the SaveSession handler

    <%@ WebHandler Language="C#" Class="SaveTab" %>
    
    using System;
    using System.Web;
    
    public class SaveTab: IHttpHandler, System.Web.SessionState.IRequiresSessionState
    {
    
        public void ProcessRequest (HttpContext context) {
            context.Response.ContentType = "text/plain";
            if (HttpContext.Current.Request.QueryString["tab"] != null)
            {
                HttpContext.Current.Session["OpenTab"] =         HttpContext.Current.Request.QueryString["tab"];
            }
    }
    
        public bool IsReusable {
            get {
                return false;
            }
        }
    }
    

    Then in the ASPX output some Javascript that selects the tab. Notice that I am outputting the session value.

    $(document).ready(function() {
      $('#tabs').tabs('select', <%= SESSION["OpenTab"]%>);
    });
    

    I hope this is enough for you to get the general idea, I can't obviously tell you exactly what to do just show you a good approach.