ASPxTabControlBase.ActiveTabChanging Event
Fires on the server side before the active tab is changed within a tab control.
Namespace: DevExpress.Web
Assembly: DevExpress.Web.v24.2.dll
Declaration
Event Data
The ActiveTabChanging event's data class is TabControlCancelEventArgs. The following properties provide information specific to this event:
Property | Description |
---|---|
Cancel | Gets or sets a value indicating whether the command which raised an event should be canceled. |
Tab | Gets a tab object related to the event. Inherited from TabControlEventArgs. |
Remarks
Write an ActiveTabChanging event handler to perform specific actions on the server side each time before the selected tab changes.
You can use the event parameter’s properties to identify the new active tab (Tab) and cancel the execution of the command if necessary (Cancel).
When a user changes the active tab, a control (ASPxTabControl or ASPxPageControl) might raise the following events:
- On the server side:
- ASPxTabControlBase.ActiveTabChanged
ASPxTabControlBase.ActiveTabChanging
- On the client side:
The following two properties control which events to generate:
- the AutoPostBack property of a control
- the processOnServer property of the client-side ActiveTabChanging event argument
Note
The processOnServer property’s default value is equal to a control’s AutoPostBack property setting.
The value of the AutoPostBack property affects the event generation logic as follows:
true
: Only the server-sideActiveTabChanging
and ActiveTabChanged events are raised. Their client-side equivalents (ActiveTabChanging and ActiveTabChanged) are not invoked.false
: The default behavior is that the client-side ActiveTabChanging and ActiveTabChanged events are raised to handle an active tab change only on the client. Optionally, you can pass event processing to handlers of the server-side event equivalents (ActiveTabChanging
and ActiveTabChanged). To do this, enable the processOnServer property in a client-side ActiveTabChanging event handler. Note that the client-side ActiveTabChanged event is not fired in this case.
You can set the Cancel property to true
in an ActiveTabChanging event handler to cancel the tab change. In this case, the server-side ActiveTabChanged event is not generated and the active tab is not changed.
Example: Use AutoPostBack to Handle Events on the Server
This example enables the AutoPostBack property to make a control process ActiveTabChanging
and ActiveTabChanged events on the server.
<dx:ASPxLabel ID="ActiveTabLabel" runat="server"/>
<dx:ASPxCheckBox ID="AllowTabChange" runat="server" Text="Allow Tab Change" Checked="True" CheckState="Checked"/>
<dx:ASPxTabControl ID="TabControl" runat="server"
AutoPostBack="True"
OnActiveTabChanging="TabControl_ActiveTabChanging"
OnActiveTabChanged="TabControl_ActiveTabChanged">
<Tabs>
<dx:Tab Text="Tab1"/>
<dx:Tab Text="Tab2"/>
<dx:Tab Text="Tab3"/>
</Tabs>
</dx:ASPxTabControl>
protected void TabControl_ActiveTabChanging(object source, DevExpress.Web.TabControlCancelEventArgs e){
//Based on the checkbox state, specify whether to cancel the tab change.
e.Cancel = !AllowTabChange.Checked;
}
protected void TabControl_ActiveTabChanged(object source, DevExpress.WebTabControlEventArgs e){
//Display the name of the active tab.
ActiveTabLabel.Text = $"Active Tab: {e.Tab.Text}";
}
Example: Use processOnServer to Pass Event Handling to the Server
This example shows how to make a control with the disabled AutoPostBack property generate the server-side ActiveTabChanging
and ActiveTabChanged events. Enable the processOnServer property in a client-side ActiveTabChanging event handler to pass event processing to the server.
<dx:ASPxLabel ID="ActiveTabLabel" runat="server"/>
<dx:ASPxCheckBox ID="AllowTabChange" runat="server" Text="Allow Tab Change" Checked="True" CheckState="Checked"/>
<dx:ASPxTabControl ID="TabControl" runat="server"
OnActiveTabChanging="TabControl_ActiveTabChanging"
OnActiveTabChanged="TabControl_ActiveTabChanged"
AutoPostBack="False">
<Tabs>
<dx:Tab Text="Tab 1"/>
<dx:Tab Text="Tab 2"/>
<dx:Tab Text="Tab 3"/>
</Tabs>
<ClientSideEvents ActiveTabChanging="function(s, e) {
//Pass tab change processing to the server.
e.processOnServer = true;
}" />
</dx:ASPxTabControl>
protected void TabControl_ActiveTabChanging(object source, DevExpress.Web.TabControlCancelEventArgs e){
//Based on the checkbox state, specify whether to cancel the tab change.
e.Cancel = !AllowTabChange.Checked;
}
protected void TabControl_ActiveTabChanged(object source, DevExpress.Web.TabControlEventArgs e){
//Display the name of the active tab.
ActiveTabLabel.Text = $"Active Tab: {e.ActiveTab.Text}";
}