LoginName.FormatString 属性

定义

提供要显示的格式项字符串。

public:
 virtual property System::String ^ FormatString { System::String ^ get(); void set(System::String ^ value); };
public virtual string FormatString { get; set; }
member this.FormatString : string with get, set
Public Overridable Property FormatString As String

属性值

String

包含用于显示用户名的格式项的字符串。 默认值为“{0}”。

例外

格式字符串无效。

示例

下面的代码示例演示如何在页面上使用该 FormatString 属性。 单击该按钮可更改显示格式。

<%@ 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 Button1_Click(Object sender, EventArgs e) {
        LoginName1.FormatString = "Welcome to our Web site, {0}";
         Button1.Visible = false;
    }

</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>ASP.NET Example</title>
</head>
<body>
    <form id="form1" runat="server">
        <p>
            <asp:LoginName id="LoginName1" runat="server" 
               FormatString ="Welcome, {0}" />
        </p>
        <p>
            <asp:Button id="Button1" onclick="Button1_Click" runat="server" 
               Text="Change Format" />
        </p>
    </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 Button1_Click(sender As Object, e As EventArgs) 
        LoginName1.FormatString = "Welcome to our Web site, {0}"
         Button1.Visible = false
    End Sub

</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>ASP.NET Example</title>
</head>
<body>
    <form id="form1" runat="server">
        <p>
            <asp:LoginName id="LoginName1" runat="server" 
               FormatString="Welcome, {0}" />
        </p>
        <p>
            <asp:Button id="Button1" onclick="Button1_Click" runat="server" 
               Text="Change Format" />
        </p>
    </form>
</body>
</html>

注解

FormatString 属性包含一个标准文本格式字符串,该字符串在网页上显示用户名。 字符串“{0}”指示在字符串中插入用户名的位置。 下表描述了可用的属性设置。

属性设置 行为
默认 (“”{0}) 当用户登录时,将显示用户的名称;否则,不会显示任何内容。
Empty 与默认值相同。 若要隐藏控件,请将 Visible 属性设置为 false.
“欢迎使用我的网站, {0}” 显示字符串“欢迎使用我的网站, 用户名”。 登录用户时。 如果未登录用户,则不会显示任何内容。
“欢迎访问我的网站。 FormatString当属性设置为字符串时,当用户登录时会显示该字符串。 由于字符串不包含“”{0},因此不显示用户的名称。 如果未登录用户,则不会显示任何内容。

设置时,此属性的值可以使用设计器工具自动保存到资源文件中。 有关详细信息,请参阅LocalizableAttribute全球化和本地化

适用于

另请参阅