日期:2014-05-20  浏览次数:20740 次

刚动态添加的那些控件,在IsPostBack为true时,又自动消失了,
刚动态添加的那些控件,在IsPostBack为true时,又自动消失了,
在某一个按钮里动态添加了几个控件,
然后在该页再点提交时,这些控件又都消失了,于是取不值!
贴点代码片断

                if   (IsPostBack)
                {
                        for   (int   i   =   0;   i   <   8;   i++)
                        {
                                Control   c   =   Page.LoadControl( "WebUserControl.ascx ");
                                this.Panel1.Controls.Add(c);
                        }
                }


-------------------------
                foreach   (Control   c   in   this.Panel1.Controls)
                {

                        //如果为用户控件,则取值,当前容器Panel1
                        if   (c.GetType().Name.Equals( "webusercontrol_ascx "))
                        {
                                //查找DropDownList1,当前容器webusercontrol_ascx

                                //住宿
                                DropDownList   ddl   =   (DropDownList)c.FindControl( "DropDownList1 ");
                                oTotal_Hotel   +=   ddl.SelectedValue.ToString()   +   ", ";

                                //早餐
                                DropDownList   ddl_breakfast   =   (DropDownList)c.FindControl( "DropDownList2 ");
                                breakfast   +=   ddl_breakfast.SelectedValue.ToString()   +   ", ";

                                //午餐
                                DropDownList   ddl_lunch   =   (DropDownList)c.FindControl( "DropDownList3 ");
                                lunch   +=   ddl_lunch.SelectedValue.ToString()   +   ", ";

                                //晚餐
                                DropDownList   ddl_dinner   =   (DropDownList)c.FindControl( "DropDownList4 ");