0

I have created 2 drop down list and 2 text boxes dynamically in asp.net .i disable text box at run time .i want that when i select item from drop down text box should be enable how to perform this task please help me :(

mrbusy
  • 9
  • 1

2 Answers2

0

On SelectedIndexChanged on the dropDownList call a function that sets the textbox enabled = true. To access controls that have been dynamically added you can use FindControl as per C#, FindControl

Community
  • 1
  • 1
guymid
  • 1,186
  • 8
  • 11
  • thanks for reply but prob is that the dropdown and textbox both of them dynamic when i true autopost property .the contols disapper, – mrbusy Aug 30 '13 at 06:32
  • Oh I see. That's because you need to recreate the controls in Init so that the ViewState can automatically populate and then your code has access to both the correct controls and the current values after PageLoad. See http://stackoverflow.com/questions/9951496/create-dynamic-controls-in-preinit-event-of-page-life-cycle and http://aspnet.4guysfromrolla.com/demos/printPage.aspx?path=/articles/092904-1.aspx – guymid Aug 30 '13 at 07:47
0

I think something like this should help you:

In your page's OnInit event:

DropDownList ddl = new DropDownList();
ddl.SelectedIndexChanged += new EventHandler(ddl_SelectedIndexChanged);
placeholder.Controls.Add(ddl); //assuming this is what you use to dynamically show the dropdown list

TextBox yourTextbox = new TextBox(); //declare the variable outside to be able to be accessed by other methods, but it must be instantiated here. declaration here is for illustration purposes only
yourTextBox.Enabled = false;
placeholder.Controls.Add(yourTextBox);

Inside the instantiated event handler:

void ddl_SelectedIndexChanged(object sender, EventArgs e)
{
    yourTextbox.Enabled = true;
}
iceheaven31
  • 877
  • 1
  • 13
  • 23