Export (0) Print
Expand All

RoleGroup.ContentTemplate Property

Gets or sets the content template associated with this role group.

Namespace:  System.Web.UI.WebControls
Assembly:  System.Web (in System.Web.dll)

[BrowsableAttribute(false)]
[PersistenceModeAttribute(PersistenceMode.InnerProperty)]
[TemplateContainerAttribute(typeof(LoginView))]
public ITemplate ContentTemplate { get; set; }

Property Value

Type: System.Web.UI.ITemplate
The ITemplate associated with this role group. The default value is null.

The ContentTemplate property contains the content that is displayed to users who are members of this role group.

The following code example dynamically creates a content template.


<%@ Page Language="C#"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
    private class CustomTemplate : ITemplate
    {
        public void InstantiateIn(System.Web.UI.Control container)
        {
            LoginName ln = new LoginName();
            LoginStatus ls = new LoginStatus();
            Literal lc = new Literal();

            lc.Text = "<br />";
            ln.FormatString = "Welcome, {0}. This line is from the template.";

            container.Controls.Add(ln);
            container.Controls.Add(lc);
            container.Controls.Add(ls);
        }
    }

    void Page_Load(Object sender, EventArgs e)
    {
        RoleGroup rg = new RoleGroup();
        rg.ContentTemplate = new CustomTemplate();
        String[] RoleList = {"users"};
        rg.Roles = RoleList;
        RoleGroupCollection rgc = LoginView1.RoleGroups;
        rgc.Add(rg);
    }

</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:LoginView id="LoginView1" runat="server">
                <AnonymousTemplate>
                    You are not logged in.<br />
                    <asp:LoginStatus id="LoginStatus1" runat="server"></asp:LoginStatus>
                </AnonymousTemplate>
                <LoggedInTemplate>
                    You are logged in as
                    <asp:LoginName id="LoginName1" runat="server" />. This message is not from the template.<br />
                    <asp:LoginStatus id="Loginstatus2" runat="server"></asp:LoginStatus>
                </LoggedInTemplate>
            </asp:LoginView>
        </form>
    </body>
</html>


.NET Framework

Supported in: 4, 3.5, 3.0, 2.0

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Community Additions

ADD
Show:
© 2014 Microsoft