我用PlaceHolder放于表单中做为控件容器,动态生成控件放在其中,我需要在点确定时,获取动态控件的相关值,该怎么办,因为我在点击确定时,页面重新初始化了,而我动态生的控件也就没有了,相关代码如下:
……
                           RadioButtonList xuanxiang=new RadioButtonList(); //生成备选项
xuanxiang.ID="xuanxing";

Hashtable hta=new Hashtable(); 
hta.Add(true,"正确");
hta.Add(false,"错误");
                            xuanxiang.DataSource =hta;
xuanxiang.DataTextField="value";
xuanxiang.DataValueField="key";
xuanxiang.DataBind ();                           ph1.controls.add("xuanxiang") //ph1 为placeholder 控件                           

解决方案 »

  1.   

    我想获得xuanxiang控件的selected 值,
      

  2.   

    用属性 数据的值用ViewState包装
      

  3.   

    另外创建一个textbox对象在客户端存储选择的信息,使用方法同hidden文本框,每次都需要重新创建你的RadioButtonList控件,提交页面后server端根据textbox.Text来确定哪个控件被选择!
      

  4.   

    你需要在POSTBACK后重新生成这些对象, but 参考DynamicControlsPlaceholder - A placeholder that saves its child controls
    http://www.denisbauer.com/ASPNETControls/DynamicControlsPlaceholder.aspx