Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

save dropdown vale on masterpage

Status
Not open for further replies.

darylbewise

Programmer
Jan 5, 2009
16
GB
I am looking to save the value of a dropdown box which is located on a masterpage when I flip between other pages that use the masterpage.

For example, all my masterpage contains is a dropdown box with a few items:

Code:
<asp:DropDownList ID="DropDownList1" runat="server">
            <asp:ListItem Text="" Value=""></asp:ListItem>
            <asp:ListItem Text="1" Value="1"></asp:ListItem>
            <asp:ListItem Text="2" Value="2"></asp:ListItem>
        </asp:DropDownList>

When a user visits page1.aspx, the following code will be executed:

Code:
protected void Page_Load(object sender, EventArgs e)
    {
        DropDownList test = (DropDownList)((MasterPage)Master).FindControl("DropDownList1");
        test.SelectedValue = "2";
    }

Then the user will visit page2.aspx. When this page is loaded, the dropdown box value on the masterpage is set back to the default and does not remain at "2".

Is there any way of getting the dropdown box to remember its value (without the use of Sessions)?
 
(without the use of Sessions)?
What's wrong with session variables? If used properly they are fine. You can also use a querystring value, a cookie or a hidden field.

I am not quite sure what you are trying to do. You have the ddl on a master page. If the user changes the ddl, you want to navigate to that page? Or if they navigate to that page directly, set the value of the ddl? Please explain further.
 
Thanks for your quick reply.

With regards to the ddl, I want its value to remain the same where ever the user is within the site.

The user can set the ddl on any page of the website, but when they navigate to another page within the website I want the ddl value to stay the same.

I am currently using Session variables, however I am currently holding around 20 different variables (from 20 different drop down boxes) => 20 different session variables.

I was just wondering if there was a way of possibly discarding the sessions in order to improve performance.
 
You will have to store the value somewhere so you can set it again. When you post back to the same page the value will remain, due to page lifecycle, however, if you navigate to a different page, you will need to read the value in and set it manually.

As for the sessions, you have to evaluate if you really need them. Do you really need to store 20 values in session? Also, based on memory of the server running the app, most likely, 20 values (small), won't eat up much memory. To make it more managable, you may want to create just one object and save that to session. For example, you can create an array list and add and remove values from it. Then you only have to store the one object in session. But I am not sure that will make any performance difference, but my help you manage session variables more easily.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top