HtmlAnchor.ServerClick 事件
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
發生於按一下 HtmlAnchor 控制項時。
public:
event EventHandler ^ ServerClick;
public event EventHandler ServerClick;
member this.ServerClick : EventHandler
Public Custom Event ServerClick As EventHandler
事件類型
範例
下列程式碼範例示範如何以宣告方式指定 和 撰寫 ServerClick 事件的事件處理常式程式碼。 HtmlAnchor按一下控制項時,會顯示訊息。
<%@ Page Language="C#" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title> HtmlAnchor ServerClick Event Example </title>
<script runat="server">
void HtmlAnchor_Click(Object sender, EventArgs e)
{
Message.InnerHtml = "Thank you for clicking the HtmlAnchor control.";
}
</script>
</head>
<body>
<form id="form1" runat="server">
<h3> HtmlAnchor ServerClick Event Example </h3>
<a id="AnchorButton"
onserverclick="HtmlAnchor_Click"
runat="server">
Click Here
</a>
<br /><br />
<span id="Message" runat="server"/>
</form>
</body>
</html>
<%@ Page Language="VB" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title> HtmlAnchor ServerClick Event Example </title>
<script runat="server">
Sub HtmlAnchor_Click(sender As Object, e As EventArgs)
Message.InnerHtml = "Thank you for clicking the HtmlAnchor control."
End Sub
</script>
</head>
<body>
<form id="form1" runat="server">
<h3> HtmlAnchor ServerClick Event Example </h3>
<a id="AnchorButton"
onserverclick="HtmlAnchor_Click"
runat="server">
Click Here
</a>
<br /><br />
<span id="Message" runat="server"/>
</form>
</body>
</html>
下列程式碼範例會修改上一個範例,以程式設計方式指定 和 撰寫 ServerClick 事件的事件處理常式程式碼。
<%@ Page Language="C#" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title> HtmlAnchor ServerClick Event Example </title>
<script runat="server">
void Page_Load(Object sender, EventArgs e)
{
// Create an EventHandler delegate for the method you want to handle the event
// and then add it to the list of methods called when the event is raised.
AnchorButton.ServerClick += new System.EventHandler(this.HtmlAnchor_Click);
}
void HtmlAnchor_Click(Object sender, EventArgs e)
{
Message.InnerHtml = "Thank you for clicking the HtmlAnchor control.";
}
</script>
</head>
<body>
<form id="form1" runat="server">
<h3> HtmlAnchor ServerClick Event Example </h3>
<a id="AnchorButton"
runat="server">
Click Here
</a>
<br /><br />
<span id="Message" runat="server"/>
</form>
</body>
</html>
<%@ Page Language="VB" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title> HtmlAnchor ServerClick Event Example </title>
<script runat="server">
Sub Page_Load(sender As Object, e As EventArgs)
' Create an EventHandler delegate for the method you want to handle the event
' and then add it to the list of methods called when the event is raised.
AddHandler AnchorButton.ServerClick, AddressOf HtmlAnchor_Click
End Sub
Sub HtmlAnchor_Click(sender As Object, e As EventArgs)
Message.InnerHtml = "Thank you for clicking the HtmlAnchor control."
End Sub
</script>
</head>
<body>
<form id="form1" runat="server">
<h3> HtmlAnchor ServerClick Event Example </h3>
<a id="AnchorButton"
runat="server">
Click Here
</a>
<br /><br />
<span id="Message" runat="server"/>
</form>
</body>
</html>
備註
按一下控制項時, HtmlAnchor 就會 ServerClick 引發 事件。 此伺服器事件會導致從用戶端往返伺服器和返回。
如需如何處理事件的詳細資訊,請參閱 處理和引發事件。