hello everyone thank you so much for providing help to me for my previous question as I'm developing application for education domain. In that I take panel control as panel1 and define a few dropdownlist controls in that panel as dropdown1, dropdown2 etc. dynamically in button1 click event and i want to use those controls' values in button2 click event help me for the same.
+1
A:
In button2_Click event, you can get dropdown's values as :
DropDownList ddl1 = (DropDownList)Page.FindControl("dropDownList1");
string dropdown1value = ddl1.SelectedValue;
But after second postback, your dynamically added controls will be lost. so you should add them in page's init event not in first button's click event.
Canavar
2009-04-05 17:51:30
That should read panel1.FindControl("dropDownList1") . If I'm not mistaken, FindControl() only scans first degree child controls.
SirDemon
2009-04-05 18:07:42
@SirDemon : No, Page.FindControl returns controls that are child of another control.
Canavar
2009-04-05 18:16:38
actually i tried bt it gves an error dat "Object reference not set to an instance of an object."
2009-04-05 19:32:44