Buy My Account


Basics
Overview
Video Demos
Pricing & Ordering
Sample Applications
Customers
News & Reviews
Download Now!

Product Tour
Product Tour
Web Applications
Mobile Applications
SharePoint Applications
Charts and Reports
Security
Architecture & Code
Team Development

Technical Materials
Training Courses
Online Help
Technical Forums
White Papers
What's New in V9.0
One Day Web Apps E-book
System Requirements
Product Roadmap
Version History

Restoring an Active Tab

Learn how to restore an active tab when navigating back to previous pages.
- Jing Ding, Senior Systems Consultant, Ohio State University Medical Center

January 25, 2010
Iron Speed Designer V6.X

Introduction

Iron Speed Designer’s generated master-detail pages put child tables in a tab container. If there are multiple tabs, the active tab is not “memorized” when navigating from page to page. However, there may be times you want the active tab memorized across page navigation. For example, if you click a row edit button on the second tab, you are redirected to an Edit Record page. After you save the changes and go back to the previous page, the page shows the first tab, but not the second tab. This article shows you how to restore the active tab across page navigation.

Solution

Since the active tab needs to be remembered across page navigation, it has to be stored in a session variable. The best place to retrieve and restore the active tab from the session variable is the page’s PreRender event handler. To store the active tab into the session variable you will have to add custom code to multiple exit points on the page. For example, within a child table, there are three table buttons (New, Edit, and Copy) and three row buttons (Edit, View, Copy). In their button click event handlers, at least one line of custom code is needed to store the active tab. If there are three child tables, the same code will be cut-and-pasted in 18 (3 x 6) places. That is a maintenance nightmare!

Fortunately, Iron Speed Designer already has a built-in single point of exit. Before redirecting to other pages, all Iron Speed Designer pages call the SaveControlsToSession() function. Generated applications use the function to store filters and search boxes of table controls. We can take advantage of this to store active tabs.

Implementation

In the page’s code-behind file (MyPage.aspx.cs or MyPage.aspx.vb), override SaveControlsToSession() and ClearContorlsFromSession() functions, and insert two lines of code in LoadData() function. That’s it.

C#:

protected override void SaveControlsToSession() {
    base.SaveControlsToSession();
 
    SaveToSession(MyTabContainer, MyTabContainer.ActiveTabIndex.ToString());
}
 
protected override void ClearControlsFromSession() {
    base.ClearControlsFromSession();
 
    RemoveFromSession(MyTabContainer);
}  
public void LoadData() {
    // LoadData reads database data and assigns it to UI controls.
    // Customize by adding code before or after the call to LoadData_Base()
    // or replace the call to LoadData_Base().
    LoadData_Base();
 
    if (InSession(MyTabContainer))
        MyContainer.ActiveTabIndex = Convert.ToInt32(GetFromSession(MyTabContainer));
}

VB .NET:

Protected Overloads Overrides Sub SaveControlsToSession()
    MyBase.SaveControlsToSession()
 
    SaveToSession(MyTabContainer, MyTabContainer.ActiveTabIndex.ToString())
End Sub
 
Protected Overloads Overrides Sub ClearControlsFromSession()
    MyBase.ClearControlsFromSession()
 
    RemoveFromSession(MyTabContainer)
End Sub
 
Public Sub LoadData()
    ' LoadData reads database data and assigns it to UI controls.
    ' Customize by adding code before or after the call to LoadData_Base()
    ' or replace the call to LoadData_Base().
    LoadData_Base()
 
    If InSession(MyTabContainer) Then
        MyTabContainer.ActiveTabIndex = Convert.ToInt32(GetFromSession(MyTabContainer))
    End If
End Sub

Please note that the active tab is restored in the LoadData() function, instead of a PreRender event handler. This is because Iron Speed Designer has its own PreRender event handler where ClearControlsFromSession() is called. If you add your own PreRender handler, it is not guaranteed to be called before Iron Speed Designer’s handler. If Iron Speed Designer’s handler is called first, the active tab is cleared from the session, and you won’t be able to restore it. Therefore, the code is moved into LoadData(), which is called before any PreRender handlers.

Conclusion

Taking advantage of Iron Speed Designer’s built-in infrastructure to restore an active tab across page navigation only requires a few lines of code in a central location.

About the Author

Jing Ding has a PhD in Computer Engineering, Bioinformatics and Computational Biology, and an M.S. in Toxicology from Iowa State University. He received his B.S. in biophysics from Fundan University in Shanghai, China. He is a self-taught programmer who "played" with assembly, C and C++ in the 1990s. He took a break from programming from 1997 to 2000. When he picked it up again in 2001, he worked with Java. Jing began working with C# and .NET in 2006.
  Support   Company Info  
 

Privacy Statement