I am trying to create an event handler which displays some text whenever a button is clicked .
I can do it using
<asp:button id="btn1" runat="server" onClick="btn1_clicked" />
<asp:label id="lbl1" runat="server" />
in the aspx.cs file
public void btn1_clicked(object sender, EventArgs e)
{
lbl1.Text = "Text goes here";
}
However when I try to create the event handler using
public void btn1_clicked(object sender, EventArgs e)
{
btn1.Click += new EventHandler(OnClick);
}
public void OnClick(object sender, EventArgs e)
{
lbl1.Text = "Text goes here";
}
It gives me an error.
What is the correct way to create the event handler?
You could create the event handler at