我知道它之前被問過,但即使我創建按鈕和事件每個OnInit我也無法讓事件發生。我在做一個Sharepoint 2010 Web部件,並用值填充一個radiobuttonlist,並在每次調用OnInit時向Web部件添加一個提交按鈕。 Page_Load方法是空的。我也嘗試將paintQnA調用放在重載的CreateChildControls中,並得到相同的結果。asp.net按鈕/ htmlbutton事件不會觸發
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
...//Get data needed to create gui
paintQnA(dr, dt, currentRow);
}
void paintQnA(DataRow dr, DataTable dt, int currentRow)
{
Panel p = new Panel();
p.ID = currentRow.ToString();
Label lbl= new Label();
lbl.Text = dr["Title"].ToString();
RadioButtonList rbl = new RadioButtonList();
rbl.ID = currentRow.ToString() + "1";
HtmlButton submitBtn = new HtmlButton();
submitBtn.ID = currentRow.ToString();
submitBtn.InnerText = "Click";
submitBtn.ServerClick += new EventHandler(submitBtn_Click);
...//fill the radiobuttonlist with data
this.Controls.Add(p);
p.Controls.Add(lbl);
p.Controls.Add(rbl);
p.Controls.Add(submitBtn);
UpdatePanel1.ContentTemplateContainer.Controls.Add(p);
}
void submitBtn_Click(object sender, EventArgs e)
{
...//Should display another dynamically created panel but is never reached.
}
使用'HtmlButton'而不是'Button'對象的任何理由? – user1
不是。只是嘗試一下按鈕,如果應該有任何區別,但仍然沒有運氣。 – mdc
你嘗試過使用'submitBtn.Click'而不是'submitBtn.ServerClick'嗎? – user1