ImageButton.TagKey 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得對應至 HtmlTextWriterTag 控制項的 ImageButton 值。
protected:
virtual property System::Web::UI::HtmlTextWriterTag TagKey { System::Web::UI::HtmlTextWriterTag get(); };
[System.ComponentModel.Browsable(false)]
protected override System.Web.UI.HtmlTextWriterTag TagKey { get; }
[<System.ComponentModel.Browsable(false)>]
member this.TagKey : System.Web.UI.HtmlTextWriterTag
Protected Overrides ReadOnly Property TagKey As HtmlTextWriterTag
屬性值
HtmlTextWriterTag 列舉值。
- 屬性
範例
下列程式碼範例示範如何覆寫 TagKey 自訂 ImageButton 控制項中的 方法,使其一律傳回 Input 標記。
注意
下列程式碼範例會使用單一檔案程式碼模型,如果直接複製到程式碼後置檔案,可能無法正常運作。 程式碼範例的第一個部分必須複製到副檔名為 .aspx 的空白文字檔。 第二個部分必須位於 C#) 的 .cs 檔案 (,或是 Visual Basic) 的 .vb 檔案 (。 如需Web Form程式碼模型的詳細資訊,請參閱ASP.NET Web Forms頁碼模型。
<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.CS.Controls" Assembly="Samples.AspNet.CS" %>
<%@ 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>Custom ImageButton - TagKey - C# Example</title>
<script runat="server">
void ImageButton1_Command(Object sender, CommandEventArgs e)
{
// Redirect to the Microsoft home page.
Response.Redirect("http://www.microsoft.com/");
}
</script>
</head>
<body>
<form id="Form1" method="post" runat="server">
<h3>Custom ImageButton - TagKey - C# Example</h3>
<aspSample:CustomImageButtonTagKey
id="ImageButton1"
runat="server"
OnCommand="ImageButton1_Command"
AlternateText="Microsoft Home"
ImageUrl="http://www.microsoft.com/homepage/gif/bnr-microsoft.gif" />
</form>
</body>
</html>
<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.VB.Controls" Assembly="Samples.AspNet.VB" %>
<%@ 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>Custom ImageButton - TagKey - VB.NET Example</title>
<script runat="server">
Sub ImageButton1_Command(sender As Object, e As CommandEventArgs)
' Redirect to the Microsoft home page.
Response.Redirect("http://www.microsoft.com/")
End Sub
</script>
</head>
<body>
<form id="Form1" method="post" runat="server">
<h3>Custom ImageButton - TagKey - VB.NET Example</h3>
<aspSample:CustomImageButtonTagKey id="ImageButton1" runat="server"
OnCommand="ImageButton1_Command" AlternateText="Microsoft Home"
ImageUrl="http://www.microsoft.com/homepage/gif/bnr-microsoft.gif" />
</form>
</body>
</html>
using System.Web;
using System.Security.Permissions;
namespace Samples.AspNet.CS.Controls
{
[AspNetHostingPermission(SecurityAction.Demand, Level = AspNetHostingPermissionLevel.Minimal)]
public sealed class CustomImageButtonTagKey : System.Web.UI.WebControls.ImageButton
{
protected override System.Web.UI.HtmlTextWriterTag TagKey
{
get
{
// Specify that only the Input HTML tag can be passed to the HtmlTextWriter.
return System.Web.UI.HtmlTextWriterTag.Input;
}
}
}
}
<AspNetHostingPermission(SecurityAction.Demand, Level:=AspNetHostingPermissionLevel.Minimal)> _
Public NotInheritable Class CustomImageButtonTagKey
Inherits System.Web.UI.WebControls.ImageButton
Protected Overrides ReadOnly Property TagKey() As System.Web.UI.HtmlTextWriterTag
Get
' Specify that only the Input HTML tag can be passed to the HtmlTextWriter.
Return System.Web.UI.HtmlTextWriterTag.Input
End Get
End Property
End Class
備註
屬性 TagKey 主要是由控制項開發人員在從 ImageButton 控制項衍生自訂類別時使用。
TagKey使用 屬性來判斷 HtmlTextWriterTag 與 控制項相關聯的 ImageButton 值。 這個屬性會覆寫基底實作,一律傳回 HtmlTextWriterTag.Input
。
適用於
另請參閱
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應