简体   繁体   中英

How to hyperlink an image in asp.net (C# / vb.net)?

I have a webpage in which I am trying to hyperlink an image. The screenshot of that section of the webpage is as follows:

在此处输入图片说明

On clicking the pdf image, it should open a pdf.

At this moment, I am able to create a pdf image which is local to my machine.


The code in .aspx file are:

<div class="row" id="divViewAssessment" runat="server">
   <div class="itemtitle">
      <asp:Label ID="litBlankAssessment" runat="server"></asp:Label>
   </div>
   <div class="itemdata">
      <asp:ImageButton ID="btnViewAssessment" runat="server" ImageUrl="~/Images/doc_pdf.gif"
         CausesValidation="False" ValidationGroup="vgrp1" Enabled="true"></asp:ImageButton>
   </div>
</div>


I am wondering what code do I need to put in .aspx.vb file ? I am sure what I need to put in .aspx but not sure what need to put in .aspx.vb (behind the code) .

The path of the pdf local to my machine is "~/Licensee/" + CStr(Session("LicenseeCode")) + "/ViewSA/Lebanon Primary Care Standards for SW.pdf" The LicenseeCode is MPHLB .

The ImageButton control is intended for triggering a postback, not navigating to a URL.

Use a HyperLink control instead. It has an ImageUrl property to set the image that is displayed, and also a NavigateUrl property to set your target URL.

You can use the following code..

Protected Sub btnViewAssessment_Click(sender As Object, e As ImageClickEventArgs) Handles btnViewAssessment.Click

    Response.Redirect("Lebanon Primary Care Standards for SW.pdf")

End Sub

Put your pdf in solution folder.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM