我在我的代码隐藏(在Page_Load中)中创建了许多CheckboxList控件,这些控件被放入UpdatePanel中。 UpdatePanel是为UpdateMode =“always”设置的,所以如果我理解正确的话,这个UpdatePanel中的每个Postback都应该在整个Updatepanel上触发一个Postback(这就是我想要的)。
简化的aspx-markup:
<asp:UpdatePanel ID="updatepanel_profiles_manualdata" runat="server">
<ContentTemplate>
<div id="cbl_container" runat="server">
</div>
</ContentTemplate>
</asp:UpdatePanel>
简化代码隐藏:
protected void create_cbl(){
// this is called in Page_Load
CheckBoxList mycbl = new CheckBoxList();
mycbl.SelectedIndexChanged += new EventHandler(cbl_manual_clickEvent);
DataTable dt3 = get_cbl_data(someparameter);
mycbl.DataSource = dt3;
mycbl.DataTextField = "Title";
mycbl.DataValueField = "ID";
mycbl.AutoPostBack = true;
mycbl.DataBind();
//add the checkboxlist to the container-div in the aspx-markup
cbl_container.Controls.Add(mycbl);
}
protected void cbl_manual_clickEvent(object sender, EventArgs e){
// do something with this click...
}
斗争:
我错过了什么?提前感谢所有提示或建议......!
答案 0 :(得分:1)
试试这个 aspx文件:
<asp:UpdatePanel ID="updatepanel_profiles_manualdata" runat="server">
<ContentTemplate>
<div id="cbl_container" runat="server">
<asp:CheckBoxList ID="CheckBoxList1" AutoPostBack="true" runat="server"></asp:CheckBoxList>
</div>
</ContentTemplate>
</asp:UpdatePanel>
背后的代码
protected void Page_Load(object sender, EventArgs e)
{
CheckBoxList1.SelectedIndexChanged += new EventHandler(cbl_manual_clickEvent);
DataTable dt3 = get_cbl_data(someparameter);
CheckBoxList1.DataSource = dt3;
CheckBoxList1.DataTextField = "Title";
CheckBoxList1.DataValueField = "ID";
CheckBoxList1.AutoPostBack = true;
CheckBoxList1.DataBind();
}
<强>#UPDATE1 强> see this answer
答案 1 :(得分:-1)
你试过做AutoPostBack=true
CheckBoxList吗?