drop down list doesn't keep state

Discussion in 'ASP .Net' started by tarscher@gmail.com, Oct 6, 2006.

  1. Guest

    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);
    }
     
    , Oct 6, 2006
    #1
    1. Advertising

  2. 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).

    --
    Gregory A. Beamer
    MVP; MCP: +I, SE, SD, DBA
    http://gregorybeamer.spaces.live.com

    *************************************************
    Think outside of the box!
    *************************************************
    <> wrote in message
    news:...
    > 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);
    > }
    >
     
    Cowboy \(Gregory A. Beamer\), Oct 6, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. SirPoonga
    Replies:
    2
    Views:
    799
    Ben Strackany
    Jan 7, 2005
  2. weiwei
    Replies:
    0
    Views:
    1,047
    weiwei
    Jan 5, 2007
  3. Replies:
    5
    Views:
    295
  4. JRough
    Replies:
    0
    Views:
    311
    JRough
    Oct 7, 2009
  5. JRough
    Replies:
    3
    Views:
    336
    Evertjan.
    Oct 7, 2009
Loading...

Share This Page