Entry
Microsoft: .NET: Visual Studio: ASP.net: Imagebutton: Map: How use imagebutton as map? [HTML / URL]
May 22nd, 2004 15:10
Knud van Eeden,
----------------------------------------------------------------------
--- Knud van Eeden --- 22 May 2004 - 11:50 pm - 00:03 am -------------
Microsoft: .NET: Visual Studio: ASP.net: Imagebutton: Map: How use
imagebutton as map? [HTML / URL]
---
Idea:
Use the OnClick method for the image button,
and put in it the command
Response.Redirect( <your URL> )
---
---
Steps: Overview:
1. -Open a new project (e.g. in Microsoft Visual Studio)
2. -Put an image button on the form
3. -Select a picture via the property 'ImageUrl'
4. -Write the following code in the OnClick event for
this imagebutton (here using visual basic)
Private Sub ImageButton1_Click(ByVal sender As System.Object,
ByVal e As System.Web.UI.ImageClickEventArgs) Handles
ImageButton1.Click
Response.Redirect("http://www.google.com")
End Sub
5. -So all together this becomes (using Microsoft Visual Studio, so
almost everything
is automatically generated in the below text)
1. the aspx file:
--- cut here ---------------------------------------------------------
<%@ Page Language="vb" AutoEventWireup="false"
Codebehind="WebForm1.aspx.vb" Inherits="WebApplication1.WebForm1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" content="Microsoft Visual
Studio.NET 7.0">
<meta name="CODE_LANGUAGE" content="Visual Basic 7.0">
<meta name="vs_defaultClientScript"
content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:ImageButton id="ImageButton1" style="Z-
INDEX: 104; LEFT: 135px; POSITION: absolute; TOP: 91px" runat="server"
ImageUrl="yourpicture.jpg"></asp:ImageButton>
</form>
</body>
</HTML>
--- cut here ---------------------------------------------------------
2. the vb file:
--- cut here ---------------------------------------------------------
Public Class WebForm1
Inherits System.Web.UI.Page
Protected WithEvents ImageButton1 As
System.Web.UI.WebControls.ImageButton
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
End Sub
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
End Sub
Private Sub ImageButton1_Click(ByVal sender As System.Object,
ByVal e As System.Web.UI.ImageClickEventArgs) Handles
ImageButton1.Click
Response.Redirect("http://www.google.com")
End Sub
End Class
--- cut here ---------------------------------------------------------
6. -If you then run it (e.g. on your server,
http://www.yourserver.com/webform1.aspx)
you see an image, which if you click on it
opens the required URL (e.g. http://www.google.com)
----------------------------------------------------------------------