如何使(链接)按钮功能作为超链接?

问题描述:

如何使用 asp:Button asp:LinkBut​​ton as asp:超链接

现有的超链接只是转到同一页面上的另一个部分: 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;
}