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 或命令名称 | 控件类型 | 必需/可选 |
---|---|---|
UserName |
任何实现 IEditableTextControl(包括 TextBox或自定义或第三方控件)的控件。 | 必需 |
Password |
任何实现 IEditableTextControl(包括 TextBox或自定义或第三方控件)的控件。 | 必需 |
RememberMe |
CheckBox | 可选 |
FailureText |
实现 ITextControl的任何控件。 | 可选 |
Login |
导致事件浮泡的任何控件。 | 可选 |
如果布局模板不包含所需控件,控件 Login 将 HttpException 引发异常。 如果向错误类型的控件提供可选控件 ID,则不会引发异常;但是,控件随后会被 Login 该控件忽略。
登录控件可以是导致事件浮泡的任何控件,例如 Button, LinkButton或 ImageButton。 控件的命令名称属性必须设置为“Login”。
当模板用于 Login 控件时,只有以下属性会影响控件的行为:
继承自 WebControl的所有属性。 (有关详细信息,请参阅 Login 控件成员 table.)
为控件设置 Login 模板时,所有其他属性都处于非活动状态。