asp link button

Posted on 2011-04-25
Last Modified: 2012-05-11
I have a ASP page with code behind and it has several linkbuttons and an image control.

Depending on which one is clicked, I want to change the imageurl on the image control on the page.

I am not sure on the best way to do this other than I know I need to set the imageurl to the new value?
Question by:kperelman
    LVL 17

    Expert Comment

    by:Carlos Villegas
    Hello, here you have a full example:
    <%@ Page Language="VB" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
    <script runat="server">
        Protected Sub LinkButton_Command(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.CommandEventArgs)
            Select Case e.CommandArgument
                Case "Image1"
                    Image1.ImageUrl = ""
                Case "Image2"
                    Image1.ImageUrl = ""
                Case "Image3"
                    Image1.ImageUrl = ""
            End Select
        End Sub
    <html xmlns="">
    <head runat="server">
        <form id="form1" runat="server">
            <asp:Image ID="Image1" runat="server" />
            <br />
            <asp:LinkButton ID="LinkButton1" runat="server" OnCommand="LinkButton_Command" CommandArgument="Image1">Image A</asp:LinkButton>
            <br />
            <asp:LinkButton ID="LinkButton2" runat="server" OnCommand="LinkButton_Command" CommandArgument="Image2">Image B</asp:LinkButton>
            <br />
            <asp:LinkButton ID="LinkButton3" runat="server" OnCommand="LinkButton_Command" CommandArgument="Image3">Image C</asp:LinkButton>

    Open in new window

    Or download the full aspx file:
    LVL 17

    Accepted Solution

    And yes, you need to set the ImageUrl property of your Image control to display that image, for example: is a valid image url that points to a google logo.

    Author Closing Comment


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
    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…
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    779 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

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now