asp.net - asp.net LinkButton OnClick 未使用 href 触发
问题描述
我有一个 LinkButton,它工作得非常好,但是当我向 LinkButton 添加一个 href 时,它会将我重定向到链接而不触发 OnClick 函数。
<asp:LinkButton target="_blank" ID="ad_main_form"
OnClick="ad_button_Click" runat="server"
CssClass="ad_main_panel" CausesValidation="False"
href="https://stackoverflow.com">
</asp:LinkButton>
如何同时触发 OnClick 和 href?
解决方案
LinkButton
has a property with name PostbackUrl
instead using href
please use this property.
To avoid all this hassle what I would have done is, call a Response.Redirect('url')
inside my click handler so it does both the jobs in a cleaner manner.
Update
Unfortunately you cannot open in new tab using Response.Redirect()
method, but you can certainly write javascript
code to open the url in a new tab. See:
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "openurl", "window.open('http://www.mywebsite.com' ,'_blank');", true);
Alternatively, you can simply do it like this:
Response.Write("<script>window.open('http://www.mywebsite.com', '_blank')</script>");
推荐阅读
- c# - Tizen .NET 可穿戴屏幕唤醒
- excel - 无法取消隐藏保存在 Excel 97 版本中的工作表
- java - 将本地文件解析为 IEditiorInput -Eclipse 插件调试器开发
- html - 在百分比范围内显示颜色阴影
- webpack - 为什么“webpack”项无法识别为 cmdlet、函数
- java - Java:存储字符串集的最佳数据结构,而不是逐个字符地重新散列
- javascript - 读取 JSON 文件
- android - 使用 Regex 获取 JSON 的一部分
- javascript - 如何从 Vue 应用程序的处理函数访问单击的元素引用?
- single-sign-on - CAS - 根据用户输入的用户名使用不同的身份验证处理程序