C# OnClick事件不发生';不能在Web部件中工作
我有一个简单的网页部件,下面有代码,但当我点击按钮时,“不接受点击”中的代码不起作用 我错过了什么或做错了什么C# OnClick事件不发生';不能在Web部件中工作,c#,sharepoint,web-parts,C#,Sharepoint,Web Parts,我有一个简单的网页部件,下面有代码,但当我点击按钮时,“不接受点击”中的代码不起作用 我错过了什么或做错了什么 public class simple_wp : WebPart { protected override void OnPreRender(EventArgs e) { base.OnPreRender(e); CreateControlHierarchy(); } private void CreateContr
public class simple_wp : WebPart
{
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
CreateControlHierarchy();
}
private void CreateControlHierarchy()
{
unAccept.Text = "Cancel";
unAccept.Click += new EventHandler(UnAcceptClick);
... some other code ... }
private void UnAcceptClick(object sender, EventArgs e)
{
... some code ...
}
protected override void CreateChildControls()
{
try
{
Controls.Add(unAccept); // button
}
catch (Exception ex)
{
Controls.Add(new LiteralControl(ex.ToString()));
}
} // # CreateChildControls #
}
将此添加到
CreateChildControls
中,您将在应用程序的呈现中的init方法中关联
protected override void CreateChildControls()
{
try
{
unAccept.Click += new EventHandler(UnAcceptClick);
Controls.Add(unAccept); // button
}
catch (Exception ex)
{
Controls.Add(new LiteralControl(ex.ToString()));
}
} //