2

At the moment I have a master page and a content page. My master page consists of a dropdownlist, from which I need to select a child from. The content page loads according the child chosen. How should I store the dropdownvalue chosen?

I don't think I can use the session, since I would like the user to be able to open multiple tabs and watch different children contents at the same time. If I can use the session in this case, I'm not sure how.

I don't think I can use the viewstate since, although it solves my multiple tabs problem, the master page and content page have a different view state.

At the moment I am using a public static variable on the content page, and I set it in the master page. But from what I've heard static variables have their values stored throughout ALL the current sessions on the site.

Question: Can any one help me by suggesting which technology should I use?

I have also heard about the 'Application' object but I don't think it makes sense to use it.

Current working Code:

(content page)

public static string Child
    {
        get
        {
            if (child == null)
                return "-1";
            return child;
        }

        set
        {
            child = value;
        }
    }

(master page)

protected void ddlChooseChild_IndexChanged(object sender, EventArgs e)
        {
            ContentPage.Child = ddlChooseChild.SelectedValue;
        }
test
  • 2,538
  • 4
  • 35
  • 52

2 Answers2

2

The best way to share data between different controls is to make use of the "Items" collection (which is a property of the HttpContext class). The collection is a Hashtable and can be accessed from your Page and User Controls like so:

Context.Items["Child"] = ddlChooseChild.SelectedValue;
duncanportelli
  • 3,161
  • 8
  • 38
  • 59
1

Unless you are restricting session by using PageID or something similar, Sessions are available on multiple tabs.

Check out this article, Master Content Page interaction

Community
  • 1
  • 1
Habib
  • 219,104
  • 29
  • 407
  • 436
  • I know the session is available on multiple tabs, but I want the SAME session variable to have different values on different tabs. Is this possible with session? – test Apr 18 '12 at 20:16
  • @test, something like this might help http://stackoverflow.com/questions/2840615/asp-net-session-multiple-browser-tabs-different-sessions – Habib Apr 18 '12 at 20:17
  • 1
    @test You can store an object in your session variable. Your object may contain whatever information you want any any number of tabs using lists, arrays, etc. – Jeremy Apr 18 '12 at 20:21