event for button

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
 
C

Christopher Reed

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
 
R

Rick Spiewak

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top