我有一张美国地图作为.gif图像。我需要对该图像进行状态选择。在WA的情况下,我将其定义为
<area href="#" runat="server" CommandArgument="WA" OnCommand="StateClicked" coords="85,27,84,35,91,33,93,24,92,16,113,23,143,30,138,51,132,71,114,68,96,66,89,64,78,64,78,64,77,56,72,49,76,40,72,37,71,26,77,24" shape="POLY"/>
但是,当我单击图像上的WA状态时,我的以下方法不会被触发。
protected void StateClicked(object sender, CommandEventArgs e)
答案 0 :(得分:1)
这是一个黑客,但您可以使用每个区域的隐藏按钮触发事件:
<强>代码隐藏:强>
protected void Page_Load(Object sender, EventArgs e)
{
areaWA.Attributes.Add("onclick", string.format("document.getElementById('{0}').click();", btnWA.ClientID))
}
protected void StateClicked(Object sender, CommandEventArgs e)
{
switch(e.CommandName)
{
case "StateClicked":
string arg = ((String)e.CommandArgument);
break;
default:
//
break;
}
}
<强>标记式强>
<area href="#" id="areaWA" runat="server" coords="85,27,84,35,91,33,93,24,92,16,113,23,143,30,138,51,132,71,114,68,96,66,89,64,78,64,78,64,77,56,72,49,76,40,72,37,71,26,77,24" shape="POLY"/>
<asp:Button id="btnWA"
style="display:none"
Text="whatever"
CommandName="StateClicked"
CommandArgument="WA"
OnCommand="StateClicked"
runat="server"/>