Login.LayoutTemplate 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得或設定用來顯示控制項 Login 的範本。
public:
virtual property System::Web::UI::ITemplate ^ LayoutTemplate { System::Web::UI::ITemplate ^ get(); void set(System::Web::UI::ITemplate ^ value); };
[System.ComponentModel.Browsable(false)]
[System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.InnerProperty)]
[System.Web.UI.TemplateContainer(typeof(System.Web.UI.WebControls.Login))]
public virtual System.Web.UI.ITemplate LayoutTemplate { get; set; }
[<System.ComponentModel.Browsable(false)>]
[<System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.InnerProperty)>]
[<System.Web.UI.TemplateContainer(typeof(System.Web.UI.WebControls.Login))>]
member this.LayoutTemplate : System.Web.UI.ITemplate with get, set
Public Overridable Property LayoutTemplate As ITemplate
屬性值
一個 ITemplate 包含顯示 Login 控制項範本的 預設值為 null。
- 屬性
範例
以下程式碼範例建立了控制項的 Login 範本。
這很重要
此範例包含一個接受使用者輸入的文字框,這可能構成安全威脅。 預設情況下,ASP.NET 網頁會驗證使用者輸入中不包含腳本或 HTML 元素。 欲了解更多資訊,請參閱 腳本漏洞概述。
<%@ Page Language="C#" AutoEventWireup="False"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>ASP.NET Example</title>
</head>
<body>
<form id="form1" runat="server">
<asp:Login id="Login1" runat="server">
<LayoutTemplate>
<table>
<tr>
<td colspan="2" align="center">
Login
</td>
</tr>
<tr>
<td colspan="2" align="center">
Enter your user name and password to log in.
</td>
</tr>
<tr>
<td>
<table>
<tr>
<td>
User name:
</td>
<td>
<asp:TextBox id="UserName" runat="server"></asp:TextBox>
<asp:requiredfieldvalidator id="UserNameRequired" runat="server" ControlToValidate="UserName" Text="*"></asp:requiredfieldvalidator>
</td>
</tr>
<tr>
<td>Password:</td>
<td>
<asp:TextBox id="Password" runat="server" textMode="Password"></asp:TextBox>
<asp:requiredfieldvalidator id="PasswordRequired" runat="server" ControlToValidate="Password" Text="*"></asp:requiredfieldvalidator>
</td>
</tr>
<tr>
<td colspan="2">
<asp:Checkbox id="RememberMe" runat="server" Text="Remember my login"></asp:Checkbox>
</td>
</tr>
</table>
</td>
<td valign="middle">
<ul>
<li><a href="newAccount.aspx">Create a new account...</a></li>
<li><a href="getPass.aspx">Forgot your password?</a></li>
<li><a href="help.aspx">Get help logging in...</a></li>
</ul>
</td>
</tr>
<tr>
<td colspan="2" align="center">
<asp:button id="Login" CommandName="Login" runat="server" Text="Login"></asp:button>
</td>
</tr>
<tr>
<td colspan="2" align="center">
<asp:Literal id="FailureText" runat="server"></asp:Literal></td>
</tr>
</table>
</LayoutTemplate>
</asp:Login>
</form>
</body>
</html>
<%@ Page Language="VB" AutoEventWireup="False"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>ASP.NET Example</title>
</head>
<body>
<form id="form1" runat="server">
<asp:Login id="Login1" runat="server">
<LayoutTemplate>
<table>
<tr>
<td colspan="2" align="center">
Login
</td>
</tr>
<tr>
<td colspan="2" align="center">
Enter your user name and password to log in.
</td>
</tr>
<tr>
<td>
<table>
<tr>
<td>
User name:
</td>
<td>
<asp:TextBox id="UserName" runat="server"></asp:TextBox>
<asp:requiredfieldvalidator id="UserNameRequired" runat="server" ControlToValidate="UserName" Text="*"></asp:requiredfieldvalidator>
</td>
</tr>
<tr>
<td>Password:</td>
<td>
<asp:TextBox id="Password" runat="server" textMode="Password"></asp:TextBox>
<asp:requiredfieldvalidator id="PasswordRequired" runat="server" ControlToValidate="Password" Text="*"></asp:requiredfieldvalidator>
</td>
</tr>
<tr>
<td colspan="2">
<asp:Checkbox id="RememberMe" runat="server" Text="Remember my login"></asp:Checkbox>
</td>
</tr>
</table>
</td>
<td valign="middle">
<ul>
<li><a href="newAccount.aspx">Create a new account...</a></li>
<li><a href="getPass.aspx">Forgot your password?</a></li>
<li><a href="help.aspx">Get help logging in...</a></li>
</ul>
</td>
</tr>
<tr>
<td colspan="2" align="center">
<asp:button id="Login" CommandName="Login" runat="server" Text="Login"></asp:button>
</td>
</tr>
<tr>
<td colspan="2" align="center">
<asp:Literal id="FailureText" runat="server"></asp:Literal></td>
</tr>
</table>
</LayoutTemplate>
</asp:Login>
</form>
</body>
</html>
備註
該 LayoutTemplate 屬性包含定義控制項如何 Login 顯示給使用者的範本。
下表列出控制範本中所需的 Login 與選用控制項。
| ID 或指令名稱 | 控制件類型 | Required/optional |
|---|---|---|
UserName |
任何實作 IEditableTextControl,包括 TextBox,或自訂或第三方控制的控制。 | Required |
Password |
任何實作 IEditableTextControl,包括 TextBox,或自訂或第三方控制的控制。 | Required |
RememberMe |
CheckBox | 可選 |
FailureText |
任何實作 ITextControl的控制。 | 可選 |
Login |
任何會導致事件冒泡的控制。 | 可選 |
如果版面範本中沒有包含所需的控制項,控制 Login 項會拋出 HttpException 例外。 如果你給錯誤類型的控制項提供可選的控制 ID,則不會拋出例外;然而,控制項隨後會被控制項忽略 Login 。
登入控制可以是任何會導致事件冒泡的控制,例如 Button、 LinkButton、 ImageButton或 。 控制項的指令名稱屬性必須設為「登入」。
當使用模板作為控制時 Login ,只有以下屬性會影響控制的行為:
所有從 繼承的 WebControl性質。 (詳情請參見 Login 控制成員表。)
當控制項設定 Login 模板時,其他所有屬性皆為非啟用。