Solved

setting default tab through cookie

Posted on 2009-07-03
6
223 Views
Last Modified: 2012-05-07
Hi everyone,

My site has six tabs using the asp.net tabcontainer. I would like, through a checkbox, to let a user  be able to set tab six as the default tab that opens up when (s)he visits the site. I imagine I need a cookie to do this? I haven't worked with cookies yet, and don't know how to code this, or whether this should be done server side or with javascript...

I'm using asp.net with C#.

TIA!
0
Comment
Question by:Feivi99
  • 3
  • 3
6 Comments
 
LVL 5

Accepted Solution

by:
Opalelement earned 400 total points
ID: 24773910
Modified form the div position cookie question:) I don't know how to set the active tab in ASP but this is a general idea.
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 null;

}
 

function setup()

{

    var tab = readCookie('tab')

// That gives the tab number (or you can use 0/1 for boolean if you only need one tab activity)

// Set the tab with code here

}

window.onload=setup;
 

/*

To set the cookie:
 

document.cookie = 'tab=' + value_variable_name + '; expires=Thu, 31 Dec 2020 23:59:59 UTC; path=/';
 

note that you don't need document.cookie +=, as it appends/replaces the new cookie on its own. 

*/

Open in new window

0
 

Author Comment

by:Feivi99
ID: 24773964
lolol. You're in good form today. I don't know where to look first :-)
0
 
LVL 5

Expert Comment

by:Opalelement
ID: 24774022
You can probably find your tab changing code here: http://forums.asp.net/p/1296454/2520410.aspx
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:Feivi99
ID: 24774132
That link enables to set up a default tab, but it would be the same for everyone, not per user. I'm pretty sure that the way to do it is with a cookie. I'll be studying the cookie dough, er, code you've given me to see if I can figure out how to incorporate the tab information..
0
 
LVL 5

Expert Comment

by:Opalelement
ID: 24774181
Well i meant specifically this part:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        TabContainer1.ActiveTab = TabContainer1.Tabs(1)
        'Take the tab index from session instead. Also, use IsPostBack for better performance
    End Sub

I think you can use that for the cookie... Not as-is, but using this line:

TabContainer1.ActiveTab = TabContainer1.Tabs(1)
0
 

Author Comment

by:Feivi99
ID: 24774309
Looking around that site, I found this,

http://forums.asp.net/p/1300797/2919897.aspx#2919897

 which is what I was looking for. And yes, it conforms to that other page.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

27 Experts available now in Live!

Get 1:1 Help Now