ASP.NET中CheckBox的事件响应
我用AJAX的ToggleButtonExtender绑定了一个CheckBox,并且希望CheckBox发生CheckedChanged事件
时改变Label的内容。我用Button代替CheckBox试过,没有问题。但是换成CheckBox以后就不响应CheckedChanged事
件了,请问是为什么?代码如下:
public partial class _Default : System.Web.UI.Page
{
Label label1 = new Label();
ToggleButtonExtender tbe = new ToggleButtonExtender();
CheckBox cb = new CheckBox();
UpdatePanel up1 = new UpdatePanel();
Panel panel1 = new Panel();
protected void Page_Load(object sender, EventArgs e)
{
label1.Width = 90;
label1.Text = "Label";
cb.ID = "cb";
cb.CheckedChanged += new EventHandler(cb_CheckedChanged);
tbe.TargetControlID = "cb";
tbe.CheckedImageUrl = "checked.png";
tbe.UncheckedImageUrl = "unchecked.png";
tbe.ImageHeight = 16;
tbe.ImageWidth = 16;
up1.ContentTemplateContainer.Controls.Add(label1);
up1.ContentTemplateContainer.Controls.Add(cb);
up1.ContentTemplateContainer.Controls.Add(tbe);
panel1.Controls.Add(up1);
panel1.Height = 100;
panel1.Width = 100;
panel1.BorderWidth = 1;
panel1.Style.Add("position", "absolute");
panel1.Style.Add("left", "200px");
panel1.Style.Add("top", "200px");
panel1.BorderColor = Color.Red;
form1.Controls.Add(panel1);
}
void cb_CheckedChanged(object sender, EventArgs e)
{
label1.Text = DateTime.Now.ToLongTimeString().ToString();
}
}
------解决方案--------------------CheckBox的autoPostpack没打开吧??