I have a simple webpart with code below, but when I click on the button code in the “UnAcceptClick” didn’t work.
What I’m missing or doing wrong?
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 #
}
Add this in your
CreateChildControls, you associate in your init method not in render of application