Export (0) Print
Expand All

View.Deactivate Event

Note: This event is new in the .NET Framework version 2.0.

Occurs when the current active View control becomes inactive.

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

public event EventHandler Deactivate
/** @event */
public void add_Deactivate (EventHandler value)

/** @event */
public void remove_Deactivate (EventHandler value)

JScript supports the use of events, but not the declaration of new ones.

The Deactivate event is raised when the current active View control becomes inactive. A View control becomes inactive when the value of the ActiveViewIndex property changes or the SetActiveView method is called to specify a different View control. For example, if View1 is the active view within a MultiView control, when the ActiveViewIndex property changes to specify View2, the Deactivate event is raised for View1 and the Activate event is raised for View2.

The following code example demonstrates how to specify and code an event handler for the Deactivate event of a View control. When the active view changes, a message is displayed to the user specifying the View control that raised the Activate event and the View control that raised the Deactivate event.

<%@ Page Language="VB" %>

<html>
<head>

    <script runat="server">

        Sub Index_Changed(ByVal Sender As Object, ByVal e As EventArgs)
            ' Set the active view to
            ' the view selected by the user.
            Dim str As String = ViewListBox.SelectedItem.Text
            Select Case (str)
                Case "DefaultView"
                    MultiView1.SetActiveView(DefaultView)
                Case "NewsView"
                    MultiView1.SetActiveView(NewsView)
                Case "ShoppingView"
                    MultiView1.SetActiveView(ShoppingView)
            End Select

        End Sub

        ' The handler for the DefaultView's Activate event.
        Sub DefaultView_Activate(ByVal sender As Object, ByVal e As EventArgs)
            ' Notify the user that the event was raised.
            ActivateLabel.Text = "The Activate event was raised for the DefaultView."
        End Sub

        ' The handler for the DefaultView's Deactivate event.
        Sub DefaultView_Deactivate(ByVal sender As Object, ByVal e As EventArgs)
            ' Notify the user that the event was raised.
            DeactivateLabel.Text = "The Deactivate event was raised for the DefaultView."
        End Sub

        ' The handler for the ShoppingView's Activate event.
        Sub ShoppingView_Activate(ByVal sender As Object, ByVal e As EventArgs)
            ' Notify the user that the event was raised.
            ActivateLabel.Text = "The Activate event was raised for the ShoppingView."
        End Sub

        ' The handler for the ShoppingView's Deactivate event.
        Sub ShoppingView_Deactivate(ByVal sender As Object, ByVal e As EventArgs)
            ' Notify the user that the event was raised.
            DeactivateLabel.Text = "The Deactivate event was raised for the ShoppingView."
        End Sub

        ' The handler for the NewsView's Activate event.
        Sub NewsView_Activate(ByVal sender As Object, ByVal e As EventArgs)
            ' Notify the user that the event was raised.
            ActivateLabel.Text = "The Activate event was raised for the NewsView."
        End Sub

        ' The handler for the NewsView's Deactivate event.
        Sub NewsView_Deactivate(ByVal sender As Object, ByVal e As EventArgs)
            ' Notify the user that the event was raised.
            DeactivateLabel.Text = "The Deactivate event was raised for the NewsView."
        End Sub

    </script>

</html>
<body>
    <form ID="Form1" runat="server">
        
        <h3>View Activate and Deactivate Events Example</h3>
        
        <h4>Select a view to display in a MultiView control:</h4>

        <asp:ListBox id="ViewListBox" 
	    Rows="1"
	    SelectionMode="Single"
	    AutoPostBack="True"
	    OnselectedIndexChanged="Index_Changed"
	    runat="Server">			 
	       <asp:ListItem Value=0>DefaultView</asp:ListItem>
	       <asp:ListItem Value=1>NewsView</asp:ListItem>
	       <asp:ListItem Value=2>ShoppingView</asp:ListItem>
	</asp:ListBox><br><br>
		   
	<hr>                 

        <asp:MultiView id="MultiView1"            
            runat="Server">

            <asp:View id="DefaultView" 
                OnActivate="DefaultView_Activate"
                OnDeactivate="DefaultView_Deactivate"                 
                runat="Server">                

                <asp:Panel id="DefaultPanel1" 
                    Width="250px" 
                    BackColor="#C0C0FF" 
                    BorderColor="#404040"
                    BorderStyle="Double"
                    runat="Server">  

                    <asp:Label id="DefaultLabel1" 
                        Font-bold="true"
                        Font-size="20" 
                        Text="The Default View"
                        runat="Server">
                    </asp:Label>              
                </asp:Panel>

            </asp:View>

            <asp:View id="NewsView" 
                OnActivate="NewsView_Activate"
                OnDeactivate="NewsView_Deactivate"
                runat="Server">

                <asp:Panel id="NewsPanel1" 
                    Width="250px"                    
                    BackColor="#C0FFC0" 
                    BorderColor="#404040"
                    BorderStyle="Double"
                    runat="Server">

                    <asp:Label id="NewsLabel1" 
                        Font-bold="true"
                        Font-size="20"
                        Text="The News View"
                        runat="Server">                    
                    </asp:Label>                   
                </asp:Panel>

            </asp:View>

            <asp:View id="ShoppingView" 
                OnActivate="ShoppingView_Activate"
                OnDeactivate="ShoppingView_Deactivate"
                runat="Server">

                <asp:Panel id="ShoppingPanel1" 
                    Width="250px" 
                    BackColor="#FFFFC0" 
                    BorderColor="#404040"
                    BorderStyle="Double"
                    runat="Server">

                    <asp:Label id="ShoppingLabel1" 
                        Font-Bold="true"
                        Font-size="20"                         
                        Text="The Shopping View"
                        runat="Server">
                    </asp:Label>                 
                </asp:Panel>

            </asp:View>

        </asp:MultiView><br><br>        

        <asp:Label ID="ActivateLabel"
            BackColor="#ffff66"
            runat="Server">
        </asp:Label><br>

        <asp:Label ID="DeactivateLabel"
            BackColor="#ffff66"
            runat="Server">
        </asp:Label>

    </form>
</body>
</html>

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

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

.NET Framework

Supported in: 2.0

Community Additions

ADD
Show:
© 2014 Microsoft