[Last Call] Learn how to a build a cloud-first strategyRegister Now


asp link button

Posted on 2011-04-25
Medium Priority
Last Modified: 2012-05-11
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?
Question by:kperelman
  • 2
LVL 17

Expert Comment

by:Carlos Villegas
ID: 35464628
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
<html xmlns="http://www.w3.org/1999/xhtml">
<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

Carlos Villegas earned 2000 total points
ID: 35464634
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.

Author Closing Comment

ID: 35471758

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

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

825 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