Learn how to a build a cloud-first strategyRegister Now


Get ImageURL or ID of a photo when clicked

Posted on 2012-09-13
Medium Priority
Last Modified: 2012-09-13
Hi  I already posted a question as to how I get the ImageUrl from an ImageButton and was advised to use CommandName.  However, I wanted to just have one method as follows:

protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        string imageName = ImageButton1.CommandName;
        imageName += ".jpg";

This would work apart from the fact that each ImageButton has a different ID - i.e they are not all called ImageButton1!  Surely there is an easy way to do this apart from manually writing a different onClick method for each ImageButton??

Some of my code is as follows:

            <asp:ImageButton CommandName="image_1" ID="ImageButton1" ImageUrl="../images/image_1.jpg" runat="server"
                Width="200px" OnClick="ImageButton1_Click" />
            <asp:ImageButton CommandName="image_2" ID="ImageButton2" ImageUrl="../images/image_2.jpg" runat="server"
                Width="200px" OnClick="ImageButton1_Click" />
            <asp:ImageButton CommandName="image_3" ID="ImageButton3" ImageUrl="../images/image_3.jpg" runat="server"
                Width="200px" OnClick="ImageButton1_Click" />

Question by:Lorna70
  • 2
LVL 60

Accepted Solution

Julian Hansen earned 1000 total points
ID: 38394786

Author Comment

ID: 38395046
Thanks Julian - you're a start - exactly what I was looking for (in your first link - didn't need to look any further :-))
LVL 60

Expert Comment

by:Julian Hansen
ID: 38395159
I enjoy being a start - thank you and you are most welcome.

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Screencast - Getting to Know the Pipeline
Suggested Courses
Course of the Month21 days, 5 hours left to enroll

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question