Justin

Justin

  • NA
  • 3
  • 0

Custom Server Control - Button Click Event

May 13 2008 5:07 PM

I cannot get the button event inside my custom server control to raise. Below is an example written in 3.5. I believe my events are in order from examples listed online. Any help?

[ToolboxData("<{0}:TestButton runat=server></{0}:TestButton>")]public class TestButton : WebControl

{

public Button Tester { get; set; }

public Label ClickedIndicator { get; set; }

protected override void CreateChildControls()
{
   base.CreateChildControls();

   Tester = new Button();
   Tester.ID =
"btnTest";
   Tester.Text =
"Increment Count";   Tester.Click += new EventHandler(Tester_Click);
   this.Controls.Add(Tester);

   ClickedIndicator =
new Label();
   ClickedIndicator.ID =
"lblClickCount";
   ClickedIndicator.Text =
"not clicked";
   this.Controls.Add(ClickedIndicator);
}

protected void Tester_Click(object sender, EventArgs e)
{
   ClickedIndicator.Text =
"clicked";
}

 


Answers (2)