How to make (link)button function as hyperlink?(如何使(链接)按钮具有超链接的功能?)
问题描述
我如何使用 asp:Button
或 asp:LinkButton
作为 asp:Hyperlink
?
How do I use an asp:Button
or asp:LinkButton
as asp:Hyperlink
?
现有的超链接只是转到同一页面上的另一个部分:NavigateUrl="#Section2"
The existing Hyperlink just goes to another section on the same page: NavigateUrl="#Section2"
我想在不需要额外编码的情况下在 aspx 文件中执行此操作.谢谢.
I want to do this in the aspx file without additional coding. Thanks.
目的是让按钮看起来而不是带下划线的文本但是我不想使用带有超链接的图像来实现此目的.
The purpose is to have a button look instead of the underlined text BUT I don't want to use an image with hyperlink to achieve this purpose.
推荐答案
可以使用 OnClientClick 事件调用 JavaScript 函数:
You can use OnClientClick event to call a JavaScript function:
<asp:Button ID="Button1" runat="server" Text="Button" onclientclick='redirect()' />
JavaScript 代码:
JavaScript code:
function redirect() {
location.href = 'page.aspx';
}
但我认为最好的方法是使用 css 设置超链接的样式.
But i think the best would be to style a hyperlink with css.
示例:
.button {
display: block;
height: 25px;
background: #f1f1f1;
padding: 10px;
text-align: center;
border-radius: 5px;
border: 1px solid #e1e1e2;
color: #000;
font-weight: bold;
}
这篇关于如何使(链接)按钮具有超链接的功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何使(链接)按钮具有超链接的功能?


- MoreLinq maxBy vs LINQ max + where 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01
- 如何用自己压缩一个 IEnumerable 2022-01-01
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- 输入按键事件处理程序 2022-01-01