views:

297

answers:

0

This is what i am currently using to remember the state but wonder if there's a better way to do this?

    <script language="javascript" type="text/javascript">
                function readCookie(name) {
                    var nameEQ = name + "=";
                    var ca = document.cookie.split(';');
                    for(var i=0;i < ca.length;i++) {
                     var c = ca[i];
                     while (c.charAt(0)==' ') c = c.substring(1,c.length);
                     if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
                    }
                    return -1;
                }


                // Code to store the last tab visited on a cookie
                function pageLoad()
                {
                    index = readCookie("activeTabReferral");

                    if (index != -1)
                    {
                        SetActiveTab(index);
                    }
                    else
                    {

                        SetActiveTab(0);
                    }
                }

                // onclick event
                function ActiveTabChanged(sender, e) { 
                    document.cookie = "activeTabReferral=" + sender.get_activeTabIndex();
                }

                // set the last clicked tab
                function SetActiveTab(tabNumber)
                {
                    var tabContainer= $find("<%=tabsReferral.ClientID %>");
                    if(tabContainer)
                    {
                        tabContainer.set_activeTabIndex(parseInt(tabNumber));
                    }
                }
        </script>

<cc1:TabContainer runat="server" ID="tabsReferral" CssClass="ajax__tab_xpsprite-theme" OnClientActiveTabChanged="ActiveTabChanged">