0
votes

I know this has been posted a guzillion times but it appears that my circumstances are slightly different since the common solution is not solving the problem. My code is as follows:

protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);

        Button btn_finishTest = new Button();
        btn_finishTest.ID = "btn_finishTest";
        btn_finishTest.Text = "Finish";
        btn_finishTest.Click += new EventHandler(btn_finishTest_Click);
        placeholder.Controls.Add(btn_finishTest);
    }

private void btn_finishTest_Click(object sender, EventArgs e) {
   // does sweet FA at the moment
}

As you can see, the button is instantiated on page-init, so I'm slightly purplexed as to why the click event code isn't executed.

1
Describe "not working" We don't have your application in front of us, so we don't know exactly what your problem is. - mason
...edited... The onclick event function isn't being executed. - J Smith
Is the button actually on the page on the client? What happens if you change btn_finishTest_Click from private to protected? - mason
button renders with no problems - no difference when changing private to protected. - J Smith

1 Answers

0
votes

In the end it was the padding of another element that was obstructing me from click the button... A stupid mistake but just thought I'd post it anyone in case anyone else comes across the same weirdness.