0

This is a trivial question, but I can't seem to find the error in my code. I have a data bound DropDownList that is connected to a SQLDataSource. For this DropDownList, I have added an EventListener to SelectedIndexChanged such that when I change the DropDownList I would like to change the text of a TextBox that I have. Here is my code:

<body>
    <form id="form1" runat="server" enableviewstate="True">
//snip

        <asp:DropDownList ID="DropDownList" runat="server" DataSourceID="SqlDataSource1" DataTextField="name" DataValueField="Id" style="z-index: 1; left: 219px; top: 199px; position: absolute" OnSelectedIndexChanged="DropDownList_SelectedIndexChanged">
        </asp:DropDownList>

        <asp:TextBox ID="TextBox1" runat="server" EnableTheming="True" style="z-index: 1; left: 218px; top: 241px; position: absolute; height: 180px; width: 240px; resize:none; right: 514px;"></asp:TextBox>
    </form>
</body>

protected void Page_Load(object sender, EventArgs e)
    {
        //Make the event listeners for our drop down lists
        DropDownList.SelectedIndexChanged += new EventHandler(this.DropDownList_SelectedIndexChanged);

        TextBox1.Text = "onwon";
    }

    protected void DropDownList_SelectedIndexChanged(object sender, EventArgs e)
    {
        TextBox1.Text = "oooooo"; //This never gets executed

    }

Thanks for your time.

SOLUTION - Enable AutoPostback to true for the drop down list. Very helpful reference can be found here: http://msdn.microsoft.com/en-us/library/ms178472.ASPX

1
  • Have you added a breakpoint and debugged to verify that it never gets called? Commented Dec 2, 2013 at 3:44

1 Answer 1

2

Your drop down list is not posting back, add the AutoPostBack="True" to your drop down list's markup, like this:

<asp:DropDownList ID="DropDownList" 
                  runat="server" 
                  DataSourceID="SqlDataSource1" 
                  DataTextField="name" 
                  DataValueField="Id" style="z-index: 1; left: 219px; top: 199px; position: absolute" 
                  OnSelectedIndexChanged="DropDownList_SelectedIndexChanged"
                  AutoPostBack="True">
</asp:DropDownList>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.