updatepanel中的服务端控件在提交更新后会丢失事件,后台也会提示找不到控件。
我的作法是在updatepanel中增加一个Panel控件:
<asp:Panel ID="Panel_ClickLine" runat="server">
</asp:Panel>
再在cs代码,中页面初始化的地方加入:
Button mybt_all_Click = new Button();
mybt_all_Click.Text = "-全部数据-";
mybt_all_Click.CommandArgument = string.Format("~/Chart/GameCategoryClickLine.aspx?AreaID={0}&CategoryID={1}&GameID={2}&p={3}&t={4}", AreaID, CategoryID, GameID, 1, WeekNumOverall - 34);
mybt_all_Click.Click += new EventHandler(mybt_all_Click_Click);
Panel_ClickLine.Controls.Add(mybt_all_Click);
来动态加入这个button控件,下面是它的事件:
void mybt_all_Click_Click(object sender, EventArgs e)
{
System.Threading.Thread.Sleep(1000);
Button bt = (Button)sender;
Image_Click.ImageUrl = bt.CommandArgument;
}