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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with the state of a DropDownList

Status
Not open for further replies.

destroyhead

Programmer
Feb 22, 2006
27
0
0
GB
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 --
 
Are you re-populating the DDL on every postback or do you use the IsPostBack method to check whether it is a postback?


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Hi ca8msm,
I am using an SQLDataSource to populate it.
How do I keep the SelectedIndex between PostBack?
Thanks.

-- Olivier --
 
Hi,
When I am doing the PostBack via ButtonClick or SelectedIndexChanged, the state stays . It is when I am doing the PostBack with the menu that the state is refreshed.
What is wrong?
Thanks.
-- Olivier --

 
I don't know - you'll have to post the relevant code so we can see what you are doing.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Yes, please post the code, a postback is a postback is a postback. It shouldn't matter what triggers it, there must be something else in the code.

Jim
 
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs" Inherits="MasterPage" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "
<html xmlns=" >
<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.
 
There isn't any!
Everything is populated automatically with the Data Control.
 
You are going to have to write the code manually if you want to manipluate it (i.e. don't populate the control on each load of the page).


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Hi,
Many thanks for your help.
Does someone know why the Menu control refresh the page without keeping the ViewState of all the other controls?
Is there a possibility to avoid that?
Thanks.

-- Olivier --
 
I just tested the menu and had no problems.. maybe just recreate the control.

Jim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top