event for button

  • Thread starter Thread starter Luke
  • Start date Start date
L

Luke

Hi

I created web control, with dynamically created buttons,
I linked them with some event (using Click event),
so when someone clicks
this events is executed. Everything is working if page is loaded
directly from server, but when I return to this page using GoBack in
browser and then I press button, nothing happens, page is reloaded
but event is not executing.
Why?
Can anybody tell me?

thanks
Lu
 
When you dynamically add a control with a corresponding event, you have to
include the event handler. For example (in C#),

Button btnGo = new Button();
btnGo.Text = "GO!";
btnGo.Click += new EventHandler(btnGo_Click);

Then, somewhere in your class, you have:

protected void btnGo_Click(Object objSender, EventArgs evtArgs)
{
<Some code goes here>
}

Hope this helps!


Christopher Reed
Web Applications Supervisor
City of Lubbock
Hi

I created web control, with dynamically created buttons,
I linked them with some event (using Click event),
so when someone clicks
this events is executed. Everything is working if page is loaded
directly from server, but when I return to this page using GoBack in
browser and then I press button, nothing happens, page is reloaded
but event is not executing.
Why?
Can anybody tell me?

thanks
Lu
 
And, of course, you have to re-create dynamically created controls on every
page load...
 
Back
Top