【发布时间】:2019-03-09 06:33:15
【问题描述】:
我有一个中继器,在项目模板内部我有一个按钮和一个锚点。
<asp:Repeater runat="server" ID="rptCategoryList" OnItemDataBound="rptCategoryList_ItemDataBound">
<ItemTemplate>
....
<div style="margin-left: 81.6%;">
<span runat="server" id="spnRegister" clientidmode="static" class="register pull-right">
<button class="btn btn-info btn-lg" style="float: ; margin-right: 40px; margin-top: -150px; background-color: #3697EA">
<a href="register.aspx" style="color: white;" target="_self">Register</a>
</button>
</span>
</div>
....
</ItemTemplate>
单击此按钮时,它会重新加载同一页面,而不是转到 register.aspx。我使用了“查看页面源”,并且href设置正确。
我移除了锚点,并为按钮添加了一个类并使用了 jQuery:
<button class="btn btn-info btn-lg registerSilver" style="float: ; margin-right: 40px; margin-top: -150px; background-color: #3697EA">
Register
</button>
$(function () {
$('.registerSilver').click(function () {debugger
window.location = 'register.aspx';
});
});
仍然无法正常工作,不断重新加载同一页面。
我什至尝试将 runat="server" 添加到超链接并将其 href 设置在转发器的 itemdatabound 中,但没有运气。
我在这里错过了什么?
【问题讨论】:
-
听起来您的按钮设置为提交,导致回发而不是重定向。尝试添加
type="button"属性,例如<button type="button" ...><a href="register.aspx" ...>Link Text</a></button>.
标签: asp.net hyperlink .net-4.5 repeater