MultiView.SetActiveView(View) Método
Definição
public:
void SetActiveView(System::Web::UI::WebControls::View ^ view);
public void SetActiveView (System.Web.UI.WebControls.View view);
member this.SetActiveView : System.Web.UI.WebControls.View -> unit
Public Sub SetActiveView (view As View)
Parâmetros
- view
- View
Um controle View para ser definido como a exibição ativa em um controle MultiView.A View control to set as the active view within a MultiView control.
Exceções
O valor do parâmetro view especificado não estava contido no controle MultiView.The specified view parameter value was not contained in the MultiView control.
Exemplos
O exemplo a seguir demonstra como criar um MultiView controle que contém três View controles.The following example demonstrates how to create a MultiView control that contains three View controls. Na primeira vez em que a página é carregada, o DefaultView é definido como o modo de exibição ativo usando o SetActiveView método.The first time the page is loaded, the DefaultView is set as the active view using the SetActiveView method. Cada View controle contém botões de link para permitir que o usuário navegue para diferentes modos de exibição.Each View control contains link buttons to allow the user to navigate to different views.
Observação
O exemplo de código a seguir usa o modelo de código de arquivo único e pode não funcionar corretamente se copiado diretamente para um arquivo code-behind.The following code sample uses the single-file code model and may not work correctly if copied directly into a code-behind file. Este exemplo de código deve ser copiado em um arquivo de texto vazio que tenha uma extensão. aspx.This code sample must be copied into an empty text file that has an .aspx extension. Para obter mais informações sobre o modelo de código Web Forms, consulte modelo de código de página do ASP.NET Web Forms.For more information on the Web Forms code model, see ASP.NET Web Forms Page Code Model.
<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>MultiView Class Example</title>
<script runat="server">
Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
' The first time the page loads,
' render the DefaultView.
If Not IsPostBack Then
' Set DefaultView as the active view.
MultiView1.SetActiveView(DefaultView)
End If
End Sub
Sub LinkButton_Command(sender As Object, e As System.Web.UI.WebControls.CommandEventArgs)
' Determine which link button was clicked
' and set the active view to
' the view selected by the user.
Select Case (e.CommandArgument)
Case "DefaultView"
MultiView1.SetActiveView(DefaultView)
Case "News"
MultiView1.SetActiveView(NewsView)
Case "Shopping"
MultiView1.SetActiveView(ShoppingView)
Case Else
Throw New Exception("You did not select a valid list item.")
End Select
End Sub
</script>
</head>
<body>
<form id="Form1" runat="server">
<h3>MultiView Class Example</h3>
<asp:MultiView id="MultiView1"
runat="Server">
<asp:View id="DefaultView"
runat="Server">
<asp:Panel id="DefaultViewPanel"
Width="330px"
BackColor="#C0C0FF"
BorderColor="#404040"
BorderStyle="Double"
runat="Server">
<asp:Label id="DefaultLabel1"
Font-bold="true"
Font-size="14"
Text="The Default View"
runat="Server"
AssociatedControlID="DefaultView">
</asp:Label>
<asp:BulletedList id="DefaultBulletedList1"
BulletStyle="Disc"
DisplayMode="Hyperlink"
Target="_blank"
runat="Server">
<asp:ListItem Value="http://www.microsoft.com">Today's Weather</asp:ListItem>
<asp:ListItem Value="http://www.microsoft.com">Today's Stock Quotes</asp:ListItem>
<asp:ListItem Value="http://www.microsoft.com">Today's News Headlines</asp:ListItem>
<asp:ListItem Value="http://www.microsoft.com">Today's Featured Shopping</asp:ListItem>
</asp:BulletedList>
<hr />
<asp:Label id="DefaultLabel2"
Font-size="12"
Text="Click a link to display a different view:"
runat="Server">
</asp:Label><br />
<asp:LinkButton id="Default_NewsLink"
Text="Go to News View"
OnCommand="LinkButton_Command"
CommandArgument="News"
CommandName="Link"
Width="150px"
runat="Server">
</asp:LinkButton>
<asp:LinkButton id="Default_ShoppingLink"
Text="Go to Shopping View"
OnCommand="LinkButton_Command"
CommandArgument="Shopping"
CommandName="Link"
Width="150px"
runat="server">
</asp:LinkButton><br /><br />
</asp:Panel>
</asp:View>
<asp:View id="NewsView"
runat="Server">
<asp:Panel id="NewsPanel1"
Width="330px"
BackColor="#C0FFC0"
BorderColor="#404040"
BorderStyle="Double"
runat="Server">
<asp:Label id="NewsLabel1"
Font-bold="true"
Font-size="14"
Text="The News View"
runat="Server"
AssociatedControlID="NewsView">
</asp:Label>
<asp:BulletedList id="NewsBulletedlist1"
BulletStyle="Disc"
DisplayMode="Hyperlink"
Target="_blank"
runat="Server">
<asp:ListItem Value="http://www.microsoft.com">Today's International Headlines</asp:ListItem>
<asp:ListItem Value="http://www.microsoft.com">Today's National Headlines</asp:ListItem>
<asp:ListItem Value="http://www.microsoft.com">Today's Local News</asp:ListItem>
</asp:BulletedList>
<hr />
<asp:Label id="NewsLabel2"
Font-size="12"
Text="Click a link to display a different view:"
runat="Server">
</asp:Label><br />
<asp:LinkButton id="News_DefaultLink"
Text="Go to the Default View"
OnCommand="LinkButton_Command"
CommandArgument="DefaultView"
CommandName="Link"
Width="150px"
runat="Server">
</asp:LinkButton>
<asp:LinkButton id="News_ShoppingLink"
Text="Go to Shopping View"
OnCommand="LinkButton_Command"
CommandArgument="Shopping"
CommandName="Link"
Width="150px"
runat="Server">
</asp:LinkButton><br /><br />
</asp:Panel>
</asp:View>
<asp:View id="ShoppingView"
runat="Server">
<asp:Panel id="ShoppingPanel1"
Width="330px"
BackColor="#FFFFC0"
BorderColor="#404040"
BorderStyle="Double"
runat="Server">
<asp:Label id="ShoppingLabel1"
Font-Bold="true"
Font-size="14"
Text="The Shopping View"
runat="Server"
AssociatedControlID="ShoppingView">
</asp:Label>
<asp:BulletedList id="ShoppingBulletedlist1"
BulletStyle="Disc"
DisplayMode="Hyperlink"
Target="_blank"
runat="Server">
<asp:ListItem Value="http://www.microsoft.com">Shop for Home and Garden </asp:ListItem>
<asp:ListItem Value="http://www.microsoft.com">Shop for Women's Fashions</asp:ListItem>
<asp:ListItem Value="http://www.microsoft.com">Shop for Men's Fashions</asp:ListItem>
</asp:BulletedList>
<hr />
<asp:Label id="ShoppingLabel2"
Font-size="12"
Text="Click a link to display a different view:"
runat="Server">
</asp:Label><br />
<asp:LinkButton id="Shopping_DefaultLink"
Text="Go to the Default View"
OnCommand="LinkButton_Command"
CommandArgument="DefaultView"
CommandName="Link"
Width="150px"
runat="Server">
</asp:LinkButton>
<asp:LinkButton id="Shopping_NewsLink"
Text="Go to News View"
OnCommand="LinkButton_Command"
CommandArgument="News"
CommandName="Link"
Width="150px"
runat="Server">
</asp:LinkButton><br /><br />
</asp:Panel>
</asp:View>
</asp:MultiView>
</form>
</body>
</html>
Comentários
Use este método para definir um View controle dentro de um MultiView controle como o modo de exibição ativo.Use this method to set a View control within a MultiView control as the active view. Somente um View controle de cada vez pode ser definido como ativo dentro de um MultiView controle.Only one View control at a time can be defined as active within a MultiView control. O View controle definido como o modo de exibição ativo é renderizado para o cliente.The View control that is set as the active view is rendered to the client. Se um View controle que não existe dentro do MultiView controle for definido como ativo, uma exceção será gerada em tempo de execução.If a View control that does not exist within the MultiView control is set as active, an exception is raised at run time. Se nenhum View controle for definido como o modo de exibição ativo, o MultiView controle não processará nenhum conteúdo para o cliente.If no View control is set as the active view, the MultiView control does not render any content to the client.
Usar o SetActiveView método para definir programaticamente o modo de exibição ativo permite que o aplicativo determine qual View controle será processado para o cliente em tempo de execução com base em critérios como a identidade e as preferências do usuário.Using the SetActiveView method to programmatically set the active view allows the application to determine which View control to render to the client at run time based on criteria such as a user's identity and preferences.
Como alternativa, você pode usar a ActiveViewIndex propriedade para obter ou definir o índice de base zero do modo de exibição ativo atual em um MultiView controle.Alternately, you can use the ActiveViewIndex property to get or set the zero-based index of the current active view in a MultiView control. Essa propriedade pode ser acessada de forma declarativa ou programaticamente.This property can be accessed either declaratively or programmatically.