Problem in Creating Dyamic Web Controls
-
Hi friends, The code is given beolow....I want to add number of controls according to the value selected in dropdownlist. But as i m inccrementing the value of ViewState variable in SelectedIndexChanged event depening on the selection.if i print that value then it is showing the correct value...but it is taking this value in the 2nd postback....not in the (current)postback caused by SelectedIndexChanged event ..... Plz tell me wat should i have to do to correct this problem..... Also if any idea about how to handle events on dynamic controls ... Thanks a lot in advance friends.:omg: public class WebForm3 : System.Web.UI.Page { protected System.Web.UI.WebControls.PlaceHolder PlaceHolder1; protected System.Web.UI.WebControls.DropDownList dd; private void Page_Load(object sender, System.EventArgs e) { if(!Page.IsPostBack) { this.NumberOfControls = 0; } else { createControls(); } } protected int NumberOfControls { get{return (int)ViewState["NumControls"];} set{ViewState["NumControls"] = value;} } public void createControls() { int cnt = this.NumberOfControls ; for (int i=0; i"));); } } //dd is a DropDownList containing values 1,2 ,3,4,5,6..... //This event is incrementing the ViewState variable to some value so as to add some more controls private void dd_SelectedIndexChanged(object sender, System.EventArgs e) { this.NumberOfControls = this.NumberOfControls + Convert.ToInt32(dd.SelectedItem.Text); //here if i print the numberofcontrols then it gives correct value.. // but on postback it is taking effect(means Taking this incremented value) after one more PostBack //TELL ME WAT SHOULD I HAVE TO DO TO CREATE DYNAMIC CONTROLS ON SELECTION FROM THIS DROPDOWNLIST } } naresh