0

I am running the following code, control was made but can not handle. Why ?

    protected void Page_Load(object sender, EventArgs e)
    {
        Button Bt = new Button();
        Bt.ID = "ButtonID";                    
        Bt.Text = "Button Text";
        Bt.Click += new EventHandler(this.test);
        i.Controls.Add(Bt);
    }

    protected void test(object sender, EventArgs e)
    {
        Label1.Text = "Test";
    }  
7
  • Welcome to StackOverflow. "but can not handle" - what does this mean? test method is not called? Commented Oct 9, 2015 at 14:49
  • 1
    The more interesting question is: what is i? What happens if you move it to Page_Init? Commented Oct 9, 2015 at 14:55
  • @TimSchmelter - Page_Load is acceptable for creation of dynamic controls. Commented Oct 9, 2015 at 15:01
  • Possible duplicate of ASP.NET Programmatically adding button with an event Commented Oct 9, 2015 at 15:06
  • I agree with @TimSchmelter, what is i? Knowing that might be all the information we need to answer this one. Commented Oct 9, 2015 at 15:13

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.