我知道之前有人问过它,但即使我在每个 OnInit 上创建按钮和事件,我也无法触发该事件。我正在做一个 Sharepoint 2010 Web 部件并用值填充单选按钮列表,并在每次调用 OnInit 时向 Web 部件添加一个提交按钮。Page_Load 方法为空。我还尝试将paintQnA 调用放在具有相同结果的重写 CreateChildControls 中。
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.
}