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!
bruce barker - 02 Mar 2008 03:47 GMT
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)
> Hi,
>
[quoted text clipped - 16 lines]
>
> Thank you!