System.Web 2.0.0.0 System.Web.UI.Control System.Web.UI.INamingContainer System.Web.UI.Themeable(true) System.Web.UI.PersistChildren(false) System.Web.UI.ParseChildren(true) System.ComponentModel.Designer("System.Web.UI.Design.WebControls.LoginViewDesigner,System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a") System.ComponentModel.DefaultProperty("CurrentView") System.ComponentModel.DefaultEvent("ViewChanged")

In this topic:

Introduction

Declarative Syntax

## Introduction

The control displays different Web site content templates (or "views") for different users, based on whether the user is authenticated and, if so, which Web site roles he or she belongs to.

If you are not familiar with the set of login controls available in ASP.NET, see ASP.NET Login Controls Overview before continuing. For a list of other topics related to login controls and membership, see Managing Users By Using Membership.

The template stored in the property is displayed to any visitor to the Web site who has not logged in. Once a user is logged in, the site displays either a template associated with one of the user's roles in the property or the default template specified in the property.

The control manages switching among the various templates once you assign templates to any of the three template properties of the class:

- Specifies the template to display to users who are not logged in to the Web site. Users who are logged in will never see this template.

- Specifies the default template to display to users who are logged in to the Web site but do not belong to any role groups with defined templates.

- Specifies the template to display to logged-in users who are members of roles with defined role-group templates. Content templates are associated with particular sets of roles in instances.

Role-group templates are searched in the order they are defined in the source. The first matching role-group template is displayed to the user. If a user is a member of more than one role, the first role-group template that matches any of the user's roles is used. If more than one template is associated with a single role, only the first defined template is used.

The following table describes the behavior of the control when various combinations of templates are used.

LoggedIn Template Property

Anonymous Template Property

RoleGroups Property

LoginView behavior

Not set

Not set

Not set

Displays no content.

Set

Not set

Not set

Displays content only when the user is logged in.

Not set

Set

Not set

Displays content only when the user is not logged in.

Not set

Not set

Set

Displays the first template in the collection that matches one of the user's roles. If no match is found, displays no content.

Set

Set

Not set

If the user is logged in, displays the template specified in the property. If the user in not logged in, displays the template specified in the property.

Set

Set

Set

If the user is logged in, displays the first template in the collection that matches one of the user's roles. If no match is found, displays the template specified in the property. If the user is not logged in, displays the template specified in the property.

Set

Not set

Set

If the user is logged in, displays the first template in the collection that matches one of the user's roles. If no match is found, displays the template specified in the property. If the user is not logged in, nothing is displayed.

Not set

Set

Set

If the user is logged in, displays the first template in the collection that matches one of the user's roles. If no match is found, nothing is displayed. If the user is not logged in, displays the template specified in the property.

The and can be used with any authentication scheme that sets the property of the object's property. You must configure role management to use the property to define templates base on the user's role on the Web site. For more information, see Understanding ASP.NET Role Management.

The method does not set the initial focus of the Web page to the control, or any of its child controls. Controls contained in the control are created after the event. To set the focus to a child control contained by the , handle the On_PreRender and call its method. You can also use the and events to programmatically access the controls in the control templates.

## Declarative Syntax

`<asp:LoginView EnableTheming="True|False" EnableViewState="True|False" ID="string" OnDataBinding="DataBinding event handler" OnDisposed="Disposed event handler" OnInit="Init event handler" OnLoad="Load event handler" OnPreRender="PreRender event handler" OnUnload="Unload event handler" OnViewChanged="ViewChanged event handler" OnViewChanging="ViewChanging event handler" runat="server" SkinID="string" Visible="True|False" > <AnonymousTemplate> <!-- child controls --> </AnonymousTemplate> <LoggedInTemplate> <!-- child controls --> </LoggedInTemplate> <RoleGroups> <asp:RoleGroup Roles="string" > <ContentTemplate> <!-- child controls --> </ContentTemplate> </asp:RoleGroup> </RoleGroups> </asp:LoginView>`

Displays the appropriate content template for a given user, based on the user's authentication status and role membership.

- Constructor
  To be added.

  Initializes a new instance of the control.

  2.0.0.0
- Property
  System.Web.UI.TemplateContainer(typeof(System.Web.UI.WebControls.LoginView))
  System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.InnerProperty)
  System.ComponentModel.DefaultValue(null)
  System.ComponentModel.Browsable(false)
  System.Web.UI.ITemplate To be added.

  The property specifies the content template to display to Web site users when they are not logged in to the Web site. This template is displayed when the property of the property is null.

  The template is never displayed to authenticated users. If the property is empty, no content is displayed to users who are not logged in.

  Gets or sets the template to display to users who are not logged in to the Web site.

  2.0.0.0
- Property
  System.Web.UI.ControlCollection To be added. To be added.

  Gets the object that contains the child controls for the control.

  2.0.0.0
- Method
  2.0.0.0
  System.Void

  The method creates the individual controls that make up the control. The set of controls created varies according to the content template displayed for the user. For example, when a user is not logged in to the Web site, only the controls contained in the template specified in the property are created.

  Creates the child controls that make up the control.

- Method
  System.Void

  Use the method to bind data from a source to the control and its children. This method resolves all data-binding expressions in the control and any child controls in the active template.

  Binds a data source to and all its child controls.

  2.0.0.0
- Property
  System.ComponentModel.Browsable(true)
  System.Boolean To be added.

  The property indicates whether themes are enabled for the control. The property also affects whether themes are enabled for the controls contained in its collection. When the property is true, the application's theme directory is searched for control skins to apply. If no skin for the particular control exists in the theme directory, a skin is not applied. When the property is false, the theme directory is not searched and the contents of the property are not used.

  A control can override the value set by its parent control, or the containing page. For example, if a parent control has set to false, you can selectively apply themes to child controls contained within the parent by setting the property to true on the individual child controls.

  Gets or sets a value indicating whether themes can be applied to the control.

  2.0.0.0
- Method
  System.Void

  The method does not set the initial focus of the Web page to the control or to any of its child controls. Controls that are contained in the control are created after the event. To set the focus to a child control contained by the , handle the On_PreRender and call its method.

  Sets input focus to a control.

  2.0.0.0
  System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)
- Method
  2.0.0.0
  System.Void `` To be added.

  This method implements .

  An that represents the control state to be restored.
- Property
  System.Web.UI.TemplateContainer(typeof(System.Web.UI.WebControls.LoginView))
  System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.InnerProperty)
  System.ComponentModel.DefaultValue(null)
  System.ComponentModel.Browsable(false)
  System.Web.UI.ITemplate To be added.

  The property is displayed to Web site users when both of the following conditions are met:

  The property of the property is not null

  The user does not belong to a role group defined in the property.

  The property specifies a default template for authenticated Web site users. If you have not configured role management, the is the only template available for authenticated users. For more information about configuring role management, see Understanding ASP.NET Role Management.

  Gets or sets the template to display to Web site users who are logged in to the Web site but are not members of one of the role groups specified in the property.

  2.0.0.0
- Method
  2.0.0.0
  System.Void ``

  The method performs initialization for the control.

  Raising an event invokes the event handler through a delegate. For more information, see Raising an Event.

  The method also allows derived classes to handle the event without attaching a delegate. This is the preferred technique for handling the event in a derived class.

  Raises the event.

  An object that contains the event data.
- Method
  2.0.0.0
  System.Void ``

  The method is called during the event to determine which content template to display to the user. If the property of the property is null, the template specified in the property is displayed; otherwise, the template associated with the user's role is displayed. If the user does not belong to a defined role group, or if you have not configured role management, the control displays the template specified in the property. For more information about configuring role management, see Role Management Providers.

  Raising an event invokes the event handler through a delegate. For more information, see Raising an Event.

  The method also allows derived classes to handle the event without attaching a delegate. This is the preferred technique for handling the event in a derived class.

  Determines which role-group template to display, based on the roles of the logged-in user.

  An object that contains the event data.
- Method
  System.Void ``

  When the control switches views, it removes the controls from the previous template and creates new child controls from the new template. The method is called after the new child controls are created.

  Use the method to perform any processing, such as data binding, necessary to initialize the controls on the new view.

  Raising an event invokes the event handler through a delegate. For more information, see Raising an Event.

  The method also allows derived classes to handle the event without attaching a delegate. This is the preferred technique for handling the event in a derived class.

  Raises the event after the control switches views.

  An object that contains the event data. 2.0.0.0
- Method
  System.Void ``

  When the controls switches views, it removes the controls from the previous template and creates new child controls from the new template. The method is called before the previous controls are removed.

  Use the method to perform any necessary processing, such as saving control information, before the controls are removed.

  Raising an event invokes the event handler through a delegate. For more information, see Raising an Event.

  The method also allows derived classes to handle the event without attaching a delegate. This is the preferred technique for handling the event in a derived class.

  Raises the event before the control switches views.

  An object that contains the event data. 2.0.0.0
- Method
  2.0.0.0
  System.Void ``

  The method is used to render the server control content to the client's browser using the specified object.

  Note This method is used primarily by control developers to extend the control.

  Renders the Web server control content to the client's browser using the specified object.

  The used to render the server control content on the client's browser.
- Property
  System.Web.UI.Themeable(false)
  System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.InnerProperty)
  System.ComponentModel.MergableProperty(false)
  System.Web.UI.Filterable(false)
  System.Web.UI.WebControls.RoleGroupCollection To be added.

  The property contains the content templates associated with various roles on the Web site. The collection in the property is searched in the order in which templates are defined in the source. The first matching role-group template is displayed to the user. If a user is a member of more than one role, the first role-group template that matches any of the user's roles is used. If more than one template is associated with a single role, only the first defined template will be used.

  If a logged-in user does not belong to any role contained in the role-group collection, the site displays the content template specified in the property. Anonymous users are never shown any template contained in the collection.

  You must configure role management to use the property to define templates based on the user's role on the Web site. For more information, see Understanding ASP.NET Role Management.

  This property cannot be set by themes or style sheet themes. For more information, see and ASP.NET Themes Overview.

  Gets a collection of role groups that associate content templates with particular roles.

  2.0.0.0
- Method
  2.0.0.0
  System.Object To be added. To be added.

  This method implements .

- Method
  System.Void `` To be added. To be added. An object containing the state of the control. 2.0.0.0
- Property
  System.ComponentModel.Browsable(true)
  System.String To be added.

  Skins available to a control are contained in one or more skin files in a theme directory. The property specifies which of these skins to apply to the control. A skin is specific to a particular control; you cannot share skin settings between controls of different types.

  If you do not set the property, a control uses the default skin if one is defined. For example, if a skin without an ID is defined for an control, then that skin applies to all controls that do not explicitly reference a skin by ID and that are not set to disable theming. If a skin with an ID is defined for an control, then that skin applies only to controls whose is set to that ID.

  If the skin files in a theme directory do not contain a skin with the specified , an exception is thrown at run time.

  Gets or sets the skin to apply to the control.

  2.0.0.0
- Event
  System.EventHandler

  When the control switches views, it removes the controls from the previous template and creates new child controls from the new template. The event is raised after the new child controls are created.

  Use the event to perform any processing, such as data binding, necessary to initialize the controls on the new view.

  The event is only raised if the login status for a user changes during a postback to the page. The event will not be raised if a user logs in using the control, or if the user logs out using the control. The event will also not occur if a user is logged in or out followed by a redirect. An example of when the event will occur is when a user is logged out by calling the method without being redirected to another page. During the next postback to the page, the control will detect the change in the login status for the user, and then raise the event.

  For more information about handling events, see Handling and Raising Events.

  Occurs after the view is changed.

  2.0.0.0
- Event
  System.EventHandler

  When the control switches views, it removes the controls from the previous template and creates new child controls from the new template. The event is raised before the previous controls are removed.

  Use the event to perform any processing, such as saving control information, necessary before the controls are removed.

  The event is only raised if the login status for a user changes during a postback to the page. The event will not be raised if a user logs in using the control, or if the user logs out using the control. The event will also not occur if a user is logged in or out followed by a redirect. An example of when the event will occur is when a user is logged out by calling the method without being redirected to another page. During the next postback to the page, the control will detect the change in the login status for the user, and then raise the event.

  For more information about handling events, see Handling and Raising Events.

  Occurs before the view is changed.

  2.0.0.0