简体   繁体   English

ASP.NET 中的超链接控件和链接控件有什么区别?

[英]What is the difference between Hyperlink control and link control in ASP.NET?

超链接控件和链接控件 ASP.NET 有什么区别?

The purpose of both controls is same.两个控件的目的是相同的。 But there is one major difference between these two, ie HTML Hyperlink control is an HTML control, whenever it is clicked the page navigates to the target page.但是这两者之间有一个主要区别,即 HTML 超链接控件是一种 HTML 控件,只要单击它,页面就会导航到目标页面。 ASP.NET Link Button control is a server control, whenever the user clicks on it, the request is redirected back to the server and in its response the page is navigated to the target page. ASP.NET Link Button 控件是一个服务器控件,每当用户单击它时,请求都会重定向回服务器,并在其响应中将页面导航到目标页面。

The HyperLink control immediately navigates to the target URL when the user clicks on the control.当用户单击控件时,HyperLink 控件会立即导航到目标 URL。 The form is not posted to the server.表单不会发布到服务器。

The LinkButton control first posts the form to the server, then navigates to the URL. LinkBut​​ton 控件首先将表单发送到服务器,然后导航到 URL。 If you need to do any server-side processing before going to the target URL, use a LinkButton.如果您需要在转到目标 URL 之前进行任何服务器端处理,请使用 LinkBut​​ton。

The <asp:Hyperlink> control is a Web server control, while the <a> link is the bare-bones HTML control. <asp:Hyperlink>控件是 Web 服务器控件,而<a>链接是基本的 HTML 控件。

Like all WebControls, the former provides a full featured programming event model, while the latter allows you to render an HTML anchor.与所有 WebControl 一样,前者提供了一个功能齐全的编程事件模型,而后者则允许您呈现一个 HTML 锚点。 You could add the runat="server" attribute to the link control to enable it to be accessed in server-side code.您可以将runat="server"属性添加到链接控件以使其能够在服务器端代码中访问。 This attribute would however be required for the Hyperlink control (because it is a ASP.NET object that renders as an <a> hyperlink in HTML.但是, Hyperlink控件需要此属性(因为它是一个 ASP.NET 对象,在 HTML 中呈现为<a>超链接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM