it is too late to hook up the event handler in Render, do it in CreateChildControls:public class WebCustomControl1 : System.Web.UI.WebControls.WebControl, INamingContainer
{
....
protected override void CreateChildControls()
{
Button bt=new Button();
bt.Text="asfaf";
bt.Click += new EventHandler(bt_Click);
                            Controls.Add(bt);
}}remove Render

解决方案 »

  1.   

    protected override void CreateChildControls()
    {
    Button bt=new Button();
    bt.Text=this.Votes.ToString();
    bt.Click += new EventHandler(bt_Click); Controls.Add(bt);
    this.Page.Response.Write(this.Votes.ToString());
    } private void bt_Click(object sender, EventArgs e)
    {
    Button bf=(Button)sender;
    bf.Text="asfafasfedasfe";
    this.Votes++;
    }
    我这样写还是不行,好像不响应按钮事件,都没变化,我已经删掉了RENDER方法,不懂,请指教
      

  2.   

    you are not a careful person, in the above code, I showed you needed to implement a er interface INamingContainer:
    public class WebCustomControl1 : System.Web.UI.WebControls.WebControl, INamingContainer^^^^^^^^^^^^^^^^^^^^^^