drop down list doesn't keep state

T

tarscher

hi all,

I have a dropdownist that doesn't keep it's selected previous state.
When I select an item i want the selected item to be selected when the
postback happened. The DDL looks like this
<asp:DropDownList ID="keywordsDropDownList" runat="server"
AutoPostBack="True"
OnSelectedIndexChanged="keywordsDropDownList_SelectedIndexChanged"
</asp:DropDownList>

Someone has an idea what I do wrong?

protected void AddButton_Click(object sender, EventArgs e)
{
myController = new Controller();
myTest = new Test(0, NameTextBox.Text,
DescriptionTextBox.Text);

NameLabel.Text = "Enter keywords for " + myTest.Name;
keywordsDropDownList.DataSource =
myController.GetKeywordTemplates();
keywordsDropDownList.DataValueField = "Id";
keywordsDropDownList.DataTextField = "KeywordParameter";
keywordsDropDownList.DataBind();

MultiView1.SetActiveView(KeywordView);
}

When the dropdownbox selection is changed:
protected void keywordsDropDownList_SelectedIndexChanged(object sender,
EventArgs e)
{
AddButton_Click(sender, e);
}
 
C

Cowboy \(Gregory A. Beamer\)

What does you Page_Load look like? A common reason for losing state is
refresh in every page load. Events (button, etc.) run AFTER Page_Load().

Are you using viewstate or is it turned off? If off, you will NOT hold state
even if you fix item #1 (if it is set up incorrectly).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,821
Latest member
AleidaSchi

Latest Threads

Top