Login.LoginButtonType 屬性

定義

取得或設定呈現 Login 按鈕時需要使用的按鈕類型。

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

其中一個 ButtonType 列舉值。 預設為 Button

例外狀況

LoginButtonType 屬性未設定為有效的 ButtonType 列舉值。

範例

下列程式碼範例顯示控制項可用的 Login 不同類型的登入按鈕。

重要

此範例包含一個文字方塊,可接受使用者輸入,這是潛在的安全性威脅。 根據預設,ASP.NET Web 網頁會驗證使用者輸入未包含指令碼或 HTML 項目。 如需詳細資訊,請參閱 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 控制項登入按鈕的按鈕類型。 下表描述不同的按鈕類型。

LoginButtonType 設定 轉譯的按鈕類型
Button HTML 按鈕,其中包含 屬性中指定的 LoginButtonText 文字。
Image 影像。 影像的 URL 是在 屬性中 LoginButtonImageUrl 指定。 屬性中指定的 LoginButtonText 字串會當做影像的替代文字使用。
Link HTML 連結,其中包含 屬性中指定的 LoginButtonText 文字。

當 屬性 LoginButtonType 設定為 ButtonLink 時,會忽略 屬性的內容 LoginButtonImageUrl

適用於

另請參閱