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;
}
这篇关于如何使(链接)按钮具有超链接的功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何使(链接)按钮具有超链接的功能?


基础教程推荐
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01