LoginName.FormatString Property

Definition

Provides a format item string to display.

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

Property Value

A string containing format items for displaying the user's name. The default value is "{0}".

Exceptions

The format string is not valid.

Examples

The following code example shows how to use the FormatString property on a page. Clicking the button changes the display format.

<%@ 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>

Remarks

The FormatString property contains a standard text format string that displays the user's name on the Web page. The string "{0}" indicates where in the string the user's name is inserted. The following table describes the available property settings.

Property setting Behavior
Default ("{0}") The user's name is displayed when the user is logged on; otherwise, nothing is displayed.
Empty Same as default. To hide the control, set the Visible property to false.
"Welcome to my site, {0}." Displays the string "Welcome to my site, username." when the user is logged in. When the user is not logged in, nothing is displayed.
"Welcome to my site." When the FormatString property is set to a string, the string is displayed when the user is logged in. Because the string does not contain "{0}", the user's name is not displayed. When the user is not logged in, nothing is displayed.

The value of this property, when set, can be saved automatically to a resource file by using a designer tool. For more information, see LocalizableAttribute and Globalization and Localization.

Applies to

See also