ImageMap.Click 事件
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
public:
event System::Web::UI::WebControls::ImageMapEventHandler ^ Click;
public event System.Web.UI.WebControls.ImageMapEventHandler Click;
member this.Click : System.Web.UI.WebControls.ImageMapEventHandler
Public Custom Event Click As ImageMapEventHandler
事件类型
示例
下面的代码示例演示如何创建包含两RectangleHotSpot个 ImageMap 对象的控件。 属性 ImageMap.HotSpotMode 设置为 HotSpotMode.PostBack
,这会导致每次用户单击某个热点区域时,页面都会发回服务器。 事件处理程序 VoteMap_Clicked
处理控件的 ImageMap click 事件。 若要使此示例正常工作,必须为 属性提供自己的映像 ImageUrl ,并相应地更新映像的路径,以便应用程序能够找到它。
<%@ page language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
void VoteMap_Clicked (Object sender, ImageMapEventArgs e)
{
string coordinates;
string hotSpotType;
int yescount = ((ViewState["yescount"] != null)? (int)ViewState["yescount"] : 0);
int nocount = ((ViewState["nocount"] != null)? (int)ViewState["nocount"] : 0);
// When a user clicks the "Yes" hot spot,
// display the hot spot's name and coordinates.
if (e.PostBackValue.Contains("Yes"))
{
yescount += 1;
coordinates = Vote.HotSpots[0].GetCoordinates();
hotSpotType = Vote.HotSpots[0].ToString ();
Message1.Text = "You selected " + hotSpotType + " " + e.PostBackValue + ".<br />" +
"The coordinates are " + coordinates + ".<br />" +
"The current vote count is " + yescount.ToString() +
" yes votes and " + nocount.ToString() + " no votes.";
}
// When a user clicks the "No" hot spot,
// display the hot spot's name and coordinates.
else if (e.PostBackValue.Contains("No"))
{
nocount += 1;
coordinates = Vote.HotSpots[1].GetCoordinates();
hotSpotType = Vote.HotSpots[1].ToString ();
Message1.Text = "You selected " + hotSpotType + " " + e.PostBackValue + ".<br />" +
"The coordinates are " + coordinates + ".<br />" +
"The current vote count is " + yescount.ToString() +
" yes votes and " + nocount.ToString() + " no votes.";
}
else
{
Message1.Text = "You did not click a valid hot spot region.";
}
ViewState["yescount"] = yescount;
ViewState["nocount"] = nocount;
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="head1" runat="server">
<title>ImageMap Class Post Back Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>ImageMap Class Post Back Example</h3>
<asp:imagemap id="Vote"
imageurl="Images/VoteImage.jpg"
width="400"
height="200"
alternatetext="Vote Yes or No"
hotspotmode="PostBack"
onclick="VoteMap_Clicked"
runat="Server">
<asp:RectangleHotSpot
top="0"
left="0"
bottom="200"
right="200"
postbackvalue="Yes"
alternatetext="Vote yes">
</asp:RectangleHotSpot>
<asp:RectangleHotSpot
top="0"
left="201"
bottom="200"
right="400"
postbackvalue="No"
alternatetext="Vote no">
</asp:RectangleHotSpot>
</asp:imagemap>
<br /><br />
<asp:label id="Message1"
runat="Server">
</asp:label>
</form>
</body>
</html>
<%@ 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">
Sub VoteMap_Clicked(ByVal sender As Object, ByVal e As ImageMapEventArgs)
Dim coordinates As String
Dim hotSpotType As String
Dim yescount As Integer
Dim nocount As Integer
If (ViewState("yescount") IsNot Nothing) Then
yescount = Convert.ToInt32(ViewState("yescount"))
Else
yescount = 0
End If
If (ViewState("nocount") IsNot Nothing) Then
nocount = Convert.ToInt32(ViewState("nocount"))
Else
nocount = 0
End If
' When a user clicks the "Yes" hot spot,
' display the hot spot's name and coordinates.
If (e.PostBackValue.Contains("Yes")) Then
yescount += 1
coordinates = Vote.HotSpots(0).GetCoordinates()
hotSpotType = Vote.HotSpots(0).ToString()
Message1.Text = "You selected " & hotSpotType & " " & e.PostBackValue & ".<br />" & _
"The coordinates are " & coordinates & ".<br />" & _
"The current vote count is " & yescount.ToString() & _
" yes votes and " & nocount.ToString() & " no votes."
' When a user clicks the "No" hot spot,
' display the hot spot's name and coordinates.
ElseIf (e.PostBackValue.Contains("No")) Then
nocount += 1
coordinates = Vote.HotSpots.Item(1).GetCoordinates()
hotSpotType = Vote.HotSpots.Item(1).ToString()
Message1.Text = "You selected " & hotSpotType & " " & e.PostBackValue & ".<br />" & _
"The coordinates are " & coordinates & ".<br />" & _
"The current vote count is " & yescount.ToString() & _
" yes votes and " & nocount.ToString() & " no votes."
Else
Message1.Text = "You did not click a valid hot spot region."
End If
ViewState("yescount") = yescount
ViewState("nocount") = nocount
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="head1" runat="server">
<title>ImageMap Class Post Back Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>ImageMap Class Post Back Example</h3>
<asp:imagemap id="Vote"
imageurl="Images/VoteImage.jpg"
width="400"
height="200"
alternatetext="Vote Yes or No"
hotspotmode="PostBack"
onclick="VoteMap_Clicked"
runat="Server">
<asp:RectangleHotSpot
top="0"
left="0"
bottom="200"
right="200"
postbackvalue="Yes"
alternatetext="Vote yes">
</asp:RectangleHotSpot>
<asp:RectangleHotSpot
top="0"
left="201"
bottom="200"
right="400"
postbackvalue="No"
alternatetext="Vote no">
</asp:RectangleHotSpot>
</asp:imagemap>
<br /><br />
<asp:label id="Message1"
runat="Server">
</asp:label>
</form>
</body>
</html>
注解
单击Click控件中的 ImageMap 对象时HotSpot,将引发 该事件。 若要允许 HotSpot 引发事件,必须先将 HotSpotModeImageMap 控件上的 属性或 HotSpotMode 对象上的 HotSpot 属性设置为 HotSpotMode.Postback
Click 。
若要以编程方式控制单击回发 HotSpot 时执行的操作,请为 Click 包含引发事件时要运行的代码的事件提供事件处理程序。
引发事件时,将通过委托调用事件处理程序。 有关如何处理事件的详细信息,请参阅 处理和引发事件。