我简单整理了一下,大概就是这个意思了。 点击按钮的时候没有反应 :(public class SPCalendar : System.Web.UI.WebControls.WebControl
{
  protected override void Render(HtmlTextWriter output)
  {
CreateChildControls();
base.Render(output);
  }
  protected override void CreateChildControls()
  {
    Button ShowMonth = new Button();
    this.ShowMonth.Click += new System.EventHandler(this.ShowMonth_Click);
    Controls.Add(ShowMonth);
  }
  private void ShowMonth_Click(object sender, System.EventArgs e)
  {
    Page.Response.Redirect("www.163.com");
  }
}

解决方案 »

  1.   

    private void GenerateButton() 

    Button button1 = new Button(); 
    button1.Text = "Test"; 
    button1.Click += new EventHandler(this.ButtonHandler); 
    this.Panel1.Controls.Add(button1); 
    ViewState["button1"] = "true"; // so just check this the next time the page is posted back 
    } after you click the dyanmically generated button. you should do this. private void Page_Load(object sender, System.EventArgs e) 

    if(Page.IsPostBack) 

    if(ViewState["button1"] != null) 
    GenerateButton(); // so you are generating the button again. 

    } your event handler will surely fire now. private void ButtonHandler(object sender, System.EventArgs e) 

    this.Label1.Text = "WORKS!";