Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations dencom on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ImageButton 1

Status
Not open for further replies.

shams123

Programmer
Jan 27, 2006
81
MY
Hi guys,

I have a page with more than 20 clickable images. I am wondering if there's any grouping mechanism for imagebuttons so that a click on any one can call the same procedure and I could retrieve the image that was clicked?

Creating onclick for each image button doesn't sound promising. As always, all help appreciated.

Thanks!
 
put all of them in a template column inside datagrid. your datagrid will be a single column datagrid

then you can use the following inside the ItemCommand

Select Case e.CommandName

Case image1clicked
'do something
Case image2clicked
'do something else
...
...
Case else
'do nothing
End Select

-DNG
 
Hi mate,

The images are going to be all over the page, no logical placement will be done. Can I still use the template column in datagrid?
 
That's an overly complicated method and not very practical. Instead, add a Handles event for each image button e.g.
Code:
Protected Sub ImageClick(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ImageButton1.Click, ImageButton2.Click etc...

    End Sub



____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Create your own sub that handles the click event of each image button you want"
Code:
    Sub ImageButtonClick(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) _
    [b]Handles ImageButton1.Click, ImageButton2.Click, ImageButton3.Click, ImageButton4.Click, ImageButton5.Click[/b]

        Dim imgButton As New ImageButton
        imgButton = sender


        Select Case imgButton.ID
            Case "ImageButton1"
                'Do Stuff
            Case "ImageButton2"
                'Do stuff
                .... etc
            Case Else
        End Select

    End Sub

JIm
 
Great one mate, works like a charm!

Cheers!
 
Thanks to ca8msm as well. I just wanted to capture the image that was clicked and then it was a common operation to do.

Cheers guys!
 
ca8msm, what you suggested was exactly something that the OP was trying to avoid...

Jim, good one...I have a make a note of it myself...star for you...

-DNG

 
ca8msm, what you suggested was exactly something that the OP was trying to avoid...

Jim, good one...I have a make a note of it myself...star for you...
No it wasn't. It was exactly the same method that Jim suggested and if you re-read my code you will see there are two image button clicks that are handled by the same function.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top