new ImageButton - no click event called

M

mihai

Hi,

I am trying to create a list of record every with an ImageButton
attached.

The code is like this:

ImageButton img = new ImageButton();
img.ImageUrl = "imgs/ok.bmp";
img.Visible = true;
img.ID = r_id.ToString();
img.Click += new
System.Web.UI.ImageClickEventHandler(this.select_Click);
Page.Form.Controls.Add(img);

The problem is that select_Click is never called at click event;
Other thing is that the code is triggered by another button click,
so is not in Page_Load() function.

Thank you!
 
B

bruce barker

asp.net web pages are stateless. a new class instance is created for
every request. this means if you add a button in one request, your code
needs to remember (via a hidden field/veiwstate/session) that created
the button and recreate on all further requests, in the oninit method.
your code will also need to attach the handler on postback (it actually
is useless to add the handler when you first create the button, as no
event will be fired that instance/request), so it exists in the class
instance recieving the postback data.

-- bruce (sqlwork.com)
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top