我有一个 .ascx 页面,我必须在其中显示 map 。
<img width="550" height="296" usemap="#Map" alt="" src="~/map_international.jpg">
<map name="Map">
<area shape="poly" coords="230,84,233,81,236,77,240,74,244,73,247,73,251,76,254,80,258,82,261,83,265,85,269,88,273,87,271,82,273,78,278,75,278,71,281,67,284,70,287,71,291,71,296,73,303,73,306,69,302,62,306,58,312,58,318,58,322,57,322,51,320,46,318,40,319,35,319,31,312,30,308,30,304,30,298,31,292,33,289,33,287,31,279,29,273,27,266,27,259,28,254,33,249,38,244,40,243,44,246,46,249,46,247,50,245,55,241,57,237,58,234,54,231,50,227,47,225,50,221,52,219,57,223,59,228,60,230,64,230,69,229,72,225,73,220,73,218,77,218,82,219,85,223,85,228,85"
href="<%# navigationURL+"id?=12" %>" alt="Europe" title="Europe" >
</map>
navigationURL 具有我在 .cs 中为其分配值的应用程序路径(代码隐藏)
我想要的只是当我在 map 中单击该区域时它应该导航到 href 中的给定路径。
但是,当我检查该区域的元素时,href 值设置为空。
但如果我在 href="www.google.com"
中硬编码值,它将导航到谷歌页面。
但是我无法从文件后面的代码传递数据
最佳答案
不确定您要做什么,因为您键入的代码甚至不应该加载页面,因为它是无效的。您似乎正在尝试使用名为 navigationURL
的公共(public)字符串来设置为 href。所以你的代码背后会有这样的东西:
public string navigationURL { get; set; }
protected void Page_Load(object sender, EventArgs e)
{
navigationURL = "someURL?id=12";
}
然后你的 href 应该是这样的:
href="<%= navigationURL %>"
尽管跳过变量 navigationURL
并从后面的代码设置 href 可能更容易。涉及在 area
上添加 id
、runat="server"
和结束标记:
<area shape="poly" coords="230,84,233,81,236,77,240,74,244,73,247,73,251,76,254,80,258,82,261,83,265,85,269,88,273,87,271,82,273,78,278,75,278,71,281,67,284,70,287,71,291,71,296,73,303,73,306,69,302,62,306,58,312,58,318,58,322,57,322,51,320,46,318,40,319,35,319,31,312,30,308,30,304,30,298,31,292,33,289,33,287,31,279,29,273,27,266,27,259,28,254,33,249,38,244,40,243,44,246,46,249,46,247,50,245,55,241,57,237,58,234,54,231,50,227,47,225,50,221,52,219,57,223,59,228,60,230,64,230,69,229,72,225,73,220,73,218,77,218,82,219,85,223,85,228,85"
id="_area" runat="server" alt="Europe" title="Europe" />
然后在后面的代码中,设置url
_area.Attributes["href"] = "SomeGreatURL";
关于javascript - 通过代码隐藏将数据传递给 <area> 标签内的 <href> 标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20660601/