我有一个转发器,里面有一个锚,但不幸的是,当用户点击图像按钮时,锚点无效。为了测试我已经在转发器之外添加了另一个锚,它工作正常,但转发器内的那个不工作。 任何评论都表示赞赏。
<asp:Repeater ID="rptrPlatforms" runat="server" OnItemDataBound="rptrPlatforms_ItemDataBound" OnItemCommand="rptrPlatforms_ItemCommand">
<ItemTemplate>
<a id="AnchorToBox" href="#BoxSelectionPos" runat="server" style="text-decoration: none">
<asp:ImageButton ID="imgPlatform" alt="" Style="" runat="server" OnCommand="Platform_Click" CommandName="PlatformClick" CommandArgument='<%# DataBinder.Eval(Container.DataItem,"PlatformLanguageID")+","+DataBinder.Eval(Container.DataItem,"PlatformID") %>' />
</a>
</ItemTemplate>
</asp:Repeater>
protected void rptrBoxes_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == (ListItemType.Item) || e.Item.ItemType == (ListItemType.AlternatingItem))
{
Image img = (Image)e.Item.FindControl("imgSetTopBox");
img.ImageUrl = "/Pages/Shop-ProductSelection/images/" + drv.Row["Image1"].ToString();
}
}
答案 0 :(得分:1)
为什么你需要拥有锚标签,为什么不将ImageButton与OnClientClick一起使用?
<asp:ImageButton FID="imgPlatform" alt="" Style="" runat="server" OnCommand="Platform_Click" CommandName="PlatformClick" CommandArgument='<%# DataBinder.Eval(Container.DataItem,"PlatformLanguageID")+","+DataBinder.Eval(Container.DataItem,"PlatformID") %>'
OnClientClick="MyPage.aspx=#BoxSelectionPos" />
答案 1 :(得分:0)
即使在javascript中使用scrollto命令,当页面滚动到上一个位置时,所有解决问题的努力都是无用的。最后,我通过在后面的代码中使用以下源来解决问题:
protected void Platform_Click(object sender, CommandEventArgs e)
{
if (e.CommandName == "PlatformClick")
{
ClientScript.RegisterStartupScript(this.GetType(), "hash", "location.hash = '#BoxSelectionPos';", true);
}
}