asp link button

I have a ASP page with vb.net 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?
kperelmanAsked:
Who is Participating?
 
Carlos VillegasConnect With a Mentor Full Stack .NET DeveloperCommented:
And yes, you need to set the ImageUrl property of your Image control to display that image, for example: http://www.google.com/images/logos/ps_logo2a_cp.png is a valid image url that points to a google logo.
0
 
Carlos VillegasFull Stack .NET DeveloperCommented:
Hello, here you have a full example:
<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<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 = "http://www.google.com/logos/2011/prokofiev11-hp.jpg"
            Case "Image2"
                Image1.ImageUrl = "http://www.google.com/images/logos/ps_logo2a_cp.png"
            Case "Image3"
                Image1.ImageUrl = "http://www.google.com/logos/2011/earthday11_hp.jpg"
        End Select
    End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <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>
    </div>
    </form>
</body>
</html>

Open in new window


Or download the full aspx file:
 ImageLink.aspx
0
 
kperelmanAuthor Commented:
Thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.