首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

刚动态添加的那些控件,在IsPostBack为true时,又自动消失了,该怎么解决

2012-01-03 
刚动态添加的那些控件,在IsPostBack为true时,又自动消失了,刚动态添加的那些控件,在IsPostBack为true时,又

刚动态添加的那些控件,在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 ");


                                dinner   +=   ddl_dinner.SelectedValue.ToString()   +   ", ";
                                                               
                        }
                        else
                        {
                                //Response.Write(c.GetType().Name+ "出错了,请与管理员联系 ");
                                //Response.End();
                        }
                }
                Response.Write( "住宿: "   +   oTotal_Hotel   +   " <hr> ");
                Response.Write( "早餐: "   +   breakfast   +   " <hr> ");
                Response.Write( "午餐: "   +   lunch   +   " <hr> ");
                Response.Write( "晚餐: "   +   dinner   +   " <hr> ");

-------------------
这两段代码分别放在
        protected   void   ImageButton3_Click(object   sender,   ImageClickEventArgs   e)


        protected   void   ImageButton5_Click(object   sender,   ImageClickEventArgs   e)

中,

求解!

一,不让它消失,
二,取它的值,我想如果不消失就按现在的办法就可以取值了,

PS:如果放在Page_Load里就没事儿,我想跟IsPostBack有关系!但具体什么关系!俺不知道!


[解决办法]
viewstate保存控件的状态怎么样啊?我只是这样想的,不过没用过

[解决办法]
up
[解决办法]
动态生成的控件是不能保持 ViewState 的.

热点排行