Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / March 2008

Tip: Looking for answers? Try searching our database.

new ImageButton - no click event called

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
mihai - 01 Mar 2008 23:36 GMT
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!

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.