Problem with the State of a DropDownList
Hi,
I have got a problem to keep the state of a DropDownList.
My page is organized this way:
- 1 MasterPage with :
- 1 DropDownList
- 1 Menu
- 1 Content
- X pages displayed into the Content when clicking on the menu
When I am clicking on the menu, the PostBack refresh the DropDownList to the SelectedIndex 0.
I want to use the selected value in the ContentPages.
I have tried with the ViewState and with cookies with no success (I guess I am using it the wrong way).
Many thanks for your help.
-- Olivier --
[567 byte] By [
destroy] at [2007-11-11 8:08:43]

# 3 Re: Problem with the State of a DropDownList
Here is my code,
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs" Inherits="MasterPage" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>MY PAGE</title>
</head>
<body>
<form id="form1" runat="server">
<!-- Zone : Header -->
<div class="header">
<!-- Zone : Direct Access -->
<div class="directaccess">
<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="DB1" DataTextField="Name" DataValueField="ID" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
</asp:DropDownList>
<asp:SqlDataSource ID="DB1" runat="server" ConnectionString="<%$ ConnectionStrings:csDB1 %>"
SelectCommand="SELECT [ID], [Name] FROM [Server]"></asp:SqlDataSource>
</div>
</div>
<div class="page">
<div id="details" style="right: 0px; top: 0px">
<div id="menu">
<asp:Menu ID="Menu1" runat="server" DataSourceID="SiteMapDataSource1" BackColor="#F7F6F3" DynamicHorizontalOffset="2" Font-Names="Verdana" Font-Size="1em" ForeColor="#7C6F57" Orientation="Horizontal" StaticSubMenuIndent="10px">
<StaticMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" />
<DynamicHoverStyle BackColor="#7C6F57" ForeColor="White" />
<DynamicMenuStyle BackColor="#F7F6F3" />
<StaticSelectedStyle BackColor="#5D7B9D" />
<DynamicSelectedStyle BackColor="#5D7B9D" />
<DynamicMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" />
<StaticHoverStyle BackColor="#7C6F57" ForeColor="White" />
</asp:Menu>
<asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" ShowStartingNode="False" />
</div>
<div id="content">
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</div>
</div>
</div>
</form>
</body>
</html>
Many thanks.
-- Olivier --