Events fired from dynamically created controls-VB.net

E

ebown5

I am programming in vb.net and haven't quite grokked how to accomplish
this task. I am a pretty proficient amateur and guessing that this is a
relatively simple problem for an experienced object oriented
programmer.

I am dynamically adding images to a webpage. Based on the data there
may be 1 to n images on any given page. I want to provide for the
ability to click on the images and direct the user to another url. I am
trying to use imagebuttons for this task.

I am having trouble handling the click event for the imagebuttons
though since they are dynamically added.

To solve this problem I tried to create a custom class called
myimagebutton that inherits from imagebutton. I figured that every time
that I dynamically created an imagebutton that I would dynamically
create an instance of the myimagebutton class instead. Myimagebutton
would have a click event, and I would handle the event accordingly.

Unfortunately, this problem is just beyond my current understanding of
custom classes and events, and the tutorials that I have read are just
not getting through to me.

Could someone please elucidate for me in simple terms how I would
create a click event for my custom class and how I would handle it? Is
creating a custom imagebutton class even the way to solve this issue?

Thanks for any light that you guys can shed on this for me.

Eric
 
A

Alessandro Zifiglio

hi Eric, Instead of an imagebutton, try and use a HyperLink control and set
its imageurl property to the url of your image. Since you do not need a
click event to occur on the serverside before you can redirect the user,
this should work out well for you. In this way you wont need to uselessly
bother with wiring up unnecessary events which you wont be using to start
with, while also avoiding a roundtrip to your server before redirecting.
Instead, in this manner, now you will be setting the NavigateUrl property to
the url you want to the user directed to.

Regards,
Alessandro Zifiglio
http://www.AsyncUI.net
 
E

ebown5

Thanks Alessandro!

That is exactly the kind of response that helps me out. I was trying to
solve a problem that quickly got very complex and I didn't realize that
there were simpler solutions out there.

I never knew that you could use hyperlinks in this way, and will put
this idea to test very soon.

Thanks again. Eric ;-)
 
E

ebown5

Thanks Alessandro!

That is exactly the kind of response that helps me out. I was trying to
solve a problem that quickly got very complex and I didn't realize that
there were simpler solutions out there.

I never knew that you could use hyperlinks in this way, and will put
this idea to test very soon.

Thanks again. Eric ;-)
 

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,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top