Click here to Skip to main content
15,394,479 members
Articles / Web Development / ASP.NET
Posted 16 Aug 2006


31 bookmarked

Achieve multiple tasks (child window) functionality in a web application using UIAPB

Rate me:
Please Sign up or sign in to vote.
4.42/5 (10 votes)
22 Aug 2006Ms-PL2 min read
Describes a solution to achieve shared session, multiple tasks functionality using the User Interface Process Application Block 2.0.


I have seen many people crying on forums for functionality for running multiple tasks by a single user while using the User Interface Process Application Block (UIPAB). Especially if it was a web application (in fact, every question did mention a web application). The official documentation of UIPAB suggests implementing the ITask interface and explicitly handling situations where multiple tasks are to be simultaneously run by a single user (no code example has been provided though). This article deals with this very problem by making some small changes to the code of UIPAB. Note that UIPAB is available for download at Microsoft’s Patterns & Practices website.

The hidden problem

There is one basic problem in achieving a multiple windows (with multiple tasks) scenario with UIPAB.

UIPAB stores the ActiveTaskID in the session variable which is shared by all browser instances from the same machine. So inherently, UIPAB can have one task active at a time (it saves the states of all the tasks but keeps only one of them active at a time). The ActiveTaskID is used in the Load event handler of the WebFormView class in order to retrieve the state of the task.

The solution

With this behavior, UIPAB can have only one task active. What we need is some way to have multiple tasks active at a single instance. This leads us to an obvious conclusion that we cannot store the ActiveTaskID in session. We need to store it with the page. I thought of storing it in the ViewState of the page. But with all the navigations happening through Response.Redirect, it becomes impossible to store the TaskID in the viewstate. Then, I decided to put the taskID in the query string of the Page Request. I had to make two changes in the code provided by Microsoft to make this happen:

  • Change in WebFormView class: replace the default GetSessionMoniker method with the following:
  • C#
    private SessionMoniker GetSessionMoniker()
        SessionMoniker sessionMoniker = null;
                sessionMoniker = SessionMoniker.GetFromSession(new Guid(Request.QueryString["taskId"]));
            catch(Exception ex)
                throw new UIPException(Resource.Exceptions.RES_ExceptionTaskNotFound);
        return sessionMoniker;
  • WebFormViewManager class: replace the ActivateView and RedirectToNextView methods with the following code:
  • C#
    public void ActivateView( string previousView, Guid taskId, string navGraph, string view )
        //  create a session moniker
        SessionMoniker sessionMoniker = new SessionMoniker( navGraph, view, taskId);
        // store the moniker into the session, so the next view can get the task information
        ViewSettings viewSettings = UIPConfiguration.Config.GetViewSettingsFromName( view ); 
        if( viewSettings == null )
            throw new UIPException(
                    Resource.Exceptions.RES_ExceptionViewConfigNotFound, view ) );
        HttpContext.Current.Session[WebFormView.CurrentTaskKey] = taskId.ToString();
        RedirectToNextView(previousView, viewSettings, taskId);
    private void RedirectToNextView(string previousView, ViewSettings viewSettings, Guid taskId)
            if (previousView == null)
                    HttpContext.Current.Request.ApplicationPath + 
                    "/" + viewSettings.Type + 
                    "?taskID=" + 
                    HttpContext.Current.Request.ApplicationPath + 
                    "/" + viewSettings.Type 
                    + "?taskID=" + 
        catch (System.Threading.ThreadAbortException) { }

Using the code

Use the code as it is. You can directly start using the modified UIP code by downloading it. Or you can make the changes yourself to the UIPAB code downloaded from Microsoft’s website.


The modifications done to UIPAB are solely by me and Microsoft has nothing to do with it. In case of any problems faced due to use of this code (specifically the features that were modified), Microsoft may not be held responsible for it. Commercial use of the code should be done only after thorough testing. I do not claim any responsibility for any erroneous behavior arising out of the use of the included code.

This article uses UIPAB 2.0. The same changes can be applied to UIPAB 1.x as well but I have not personally done so.


This article, along with any associated source code and files, is licensed under The Microsoft Public License (Ms-PL)


About the Author

Deobrat Singh
Software Developer Microsoft India
India India
I am a developer (okay... that's very obvious!). I started programming at the age of 17 when I entered my engineering graduation back in the year 2001. I started off with C, C++ on UNIX. But soon I realized that if I need to make money out of my skills, I need to add some visual element to my applications (and that I need to switch to MS technologies!). Someone told me about VB. I started learning it but couldn’t get thru (I was religiously in love with curly braces; I never felt VB is a language). Then I began with VC++ 6.0 and I fell in love with it. Since then, I have been working on various MS technologies (C++, C#, VB.NET, SQL Server 2000/2005 etc.) I graduated in 2005 and currently, I am working with Microsoft in Hyderabad, India.
That’s all I can write as of now. If you want to know more, drop me a mail, I will try and respond Smile | :)

Comments and Discussions

-- There are no messages in this forum --