0

Im using C# in VS 2010 to develop a web page.

the below is what i used to develop the dynamic text box for a certain drop down option...the problem im facing is that the text box is not being generated when i select the option.It is generated only when i clik a button or do some activity.

What changes should i do OR where to place the code to generate the text box as soon i select the option in the drop down control

        TextBox new_textbox = new TextBox();
        new_textbox.ID = "txt" + 1;
        new_textbox.Text = "";
        PlaceHolder1.Controls.Add(new_textbox);
        Label5.Visible = true;
5
  • 1
    Is that code fired when the selected index of your drop down changes? Commented Jun 1, 2012 at 16:45
  • Debug and see what property new_textbox has a value that might cause the issue (for example: location, visibility, size) Commented Jun 1, 2012 at 16:45
  • sry,i didn get u. what is the problem in that? Commented Jun 1, 2012 at 16:46
  • yes it is in "DropDownList1_SelectedIndexChanged" Commented Jun 1, 2012 at 16:48
  • As Abe says. Where in your code is that piece fired? is it on DDL changed? or happening only on postback? You would still be better off doing this with jquery. Commented Jun 1, 2012 at 16:48

1 Answer 1

1

set AutoPostBack="True" in your dropdownlist

<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True">

When AutoPostBack Property is set to 'true' a postback to the server occurs automatically whenever the user selects an item from the list. By default it is set to 'false'.

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.