Login.LoginButtonType 属性
定义
public:
virtual property System::Web::UI::WebControls::ButtonType LoginButtonType { System::Web::UI::WebControls::ButtonType get(); void set(System::Web::UI::WebControls::ButtonType value); };
public virtual System.Web.UI.WebControls.ButtonType LoginButtonType { get; set; }
member this.LoginButtonType : System.Web.UI.WebControls.ButtonType with get, set
Public Overridable Property LoginButtonType As ButtonType
属性值
ButtonType 枚举值之一。One of the ButtonType enumeration values. 默认为 Button。The default is Button.
例外
未将 LoginButtonType 属性设置为有效的 ButtonType 枚举值。The LoginButtonType property is not set to a valid ButtonType enumeration value.
示例
下面的代码示例演示可用于控件的登录按钮的不同类型 Login 。The following code example shows the different types of login buttons available for the Login control.
重要
此示例包含一个文本框,该文本框接受用户输入,这是一个潜在的安全威胁。This example contains a text box that accepts user input, which is a potential security threat. 默认情况下,ASP.NET 网页验证用户输入是否不包含脚本或 HTML 元素。By default, ASP.NET Web pages validate that user input does not include script or HTML elements. 有关详细信息,请参阅脚本侵入概述。For more information, see Script Exploits Overview.
<%@ 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">
void changeButton_Click(Object sender, EventArgs e)
{
if (ChooseButtonType.SelectedValue == "Button")
{
Login1.LoginButtonType = ButtonType.Button;
}
if (ChooseButtonType.SelectedValue == "Image")
{
Login1.LoginButtonType = ButtonType.Image;
}
if (ChooseButtonType.SelectedValue == "Link")
{
Login1.LoginButtonType = ButtonType.Link;
}
Login1.LoginButtonText = Server.HtmlEncode(buttonText.Text);
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>ASP.NET Example</title>
</head>
<body>
<form id="form1" runat="server">
<table>
<tr>
<td>Login Button Text:
</td>
<td>
<asp:TextBox id="buttonText"
runat="server"
Text="Login"></asp:TextBox>
</td>
<td>Button Type:
</td>
<td>
<asp:DropDownList id="ChooseButtonType"
runat="server">
<asp:ListItem value="Button"
selected="true"></asp:ListItem>
<asp:ListItem value="Image"></asp:ListItem>
<asp:ListItem value="Link"></asp:ListItem>
</asp:DropDownList>
</td>
<td>
<asp:Button id="changeButton" runat="server" Text="Change" OnClick="changeButton_Click"></asp:Button>
</td>
</tr>
<tr>
<td colspan="4"
align="center">
<asp:Login id="Login1"
runat="server"
LoginButtonType="Image"
LoginButtonText="Log in to Web Site."
LoginButtonImageUrl="images\login.png">
</asp:Login>
</td>
</tr>
</table>
</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">
Sub changeButton_Click(ByVal sender As Object, ByVal e As System.EventArgs)
If (ChooseButtonType.SelectedValue = "Button") Then
Login1.LoginButtonType = System.Web.UI.WebControls.ButtonType.Button
End If
If (ChooseButtonType.SelectedValue = "Image") Then
Login1.LoginButtonType = System.Web.UI.WebControls.ButtonType.Image
End If
If (ChooseButtonType.SelectedValue = "Link") Then
Login1.LoginButtonType = System.Web.UI.WebControls.ButtonType.Link
End If
Login1.LoginButtonText = Server.HtmlEncode(buttonText.Text)
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>ASP.NET Example</title>
</head>
<body>
<form id="Form1" runat="server">
<table>
<tr>
<td>Login Button Text:
</td>
<td>
<asp:TextBox id="buttonText"
runat="server"
Text="Login"></asp:TextBox>
</td>
<td>Button Type:
</td>
<td>
<asp:DropDownList id="ChooseButtonType"
runat="server">
<asp:ListItem value="Button"
selected="true"></asp:ListItem>
<asp:ListItem value="Image"></asp:ListItem>
<asp:ListItem value="Link"></asp:ListItem>
</asp:DropDownList>
</td>
<td>
<asp:Button id="changeButton" runat="server" Text="Change" OnClick="changeButton_Click"></asp:Button>
</td>
</tr>
<tr>
<td colspan="4"
align="center">
<asp:Login id="Login1"
runat="server"
LoginButtonType="Image"
LoginButtonText="Log in to Web Site."
LoginButtonImageUrl="images\login.png">
</asp:Login>
</td>
</tr>
</table>
</form>
</body>
</html>
注解
LoginButtonType属性确定要用于 Login 控件的登录按钮的按钮类型。The LoginButtonType property determines the type of button to use for the Login control's login button. 下表描述了不同的按钮类型。The following table describes the different button types.
| LoginButtonType 设置LoginButtonType setting | 呈现的按钮类型Type of button rendered |
|---|---|
| Button | 一个 HTML 按钮,其中包含属性中指定的文本 LoginButtonText 。An HTML button with the text specified in the LoginButtonText property. |
| Image | 图像。An image. 图像的 URL 在属性中指定 LoginButtonImageUrl 。The URL of the image is specified in the LoginButtonImageUrl property. 属性中指定的字符串用作 LoginButtonText 图像的替代文本。The string specified in the LoginButtonText property is used as alternate text for the image. |
| Link | 具有属性中指定的文本的 HTML 链接 LoginButtonText 。An HTML link with the text specified in the LoginButtonText property. |
当 LoginButtonType 属性设置为或时 Button Link ,将忽略属性的内容 LoginButtonImageUrl 。When the LoginButtonType property is set to Button or Link, the content of the LoginButtonImageUrl property is ignored.