0
我有這段代碼。當我點擊任何按鈕不起作用。我想要所有按鈕都運行EventHandler(Button1_Click)。我試圖使用多個AsyncPostBackTrigger,但隨後計時器方法卡住了。帶有定時器的updatepanel中的按鈕不起作用
public DataTable data1 = new DataTable();
protected void Timer1_Tick(object sender, EventArgs e){
MySqlConnection con = openconnection();
MySqlDataAdapter sda1 = new MySqlDataAdapter("SELECT id FROM orderprogress WHERE Order=0;", con);
sda1.Fill(data1);
for (int i = 0; i < data1.Rows.Count; i++){
TableRow row = new TableRow();
TableCell cell1 = new TableCell();
cell1.Text = data1.Rows[i][0].ToString();
row.Cells.Add(cell1);
Table1.Rows.Add(row);
insertbuttons(i);
}
}
void insertbuttons(int i){
Button btn = new Button();
btn.ID = data1.Rows[i][0].ToString();
btn.Text = "Apply!";
btn.Click += new EventHandler(Button1_Click);
TableRow row1 = new TableRow();
TableCell cell2 = new TableCell();
row1.Cells.Add(cell2);
Table1.Rows[i].Cells[1].Controls.Add(btn);
}
protected void Button1_Click(object sender, EventArgs e){
orderidlb.Text = "button pressed";
}
這裏的ASP代碼,我用:晚期
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:Timer ID="Timer1" runat="server" OnTick="Timer1_Tick" Interval="10"></asp:Timer>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" AutoPostBack="True" UpdateMode="Conditional" ChildrenAsTriggers="true">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
</Triggers>
<ContentTemplate>
<asp:Table ID="Table1" runat="server">
<asp:TableRow>
<asp:TableCell>ID</asp:TableCell>
<asp:TableCell>test BTN!</asp:TableCell>
</asp:TableRow>
</asp:Table>
</ContentTemplate>
</asp:UpdatePanel>
您是否在按鈕上嘗試過AutoPostBack =「true」? – Seano666