Share via


Registration Approval Page Load

Retired Content

This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This page may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.

The page load process begins when a manager submits an HTTP request to begin the registration approval process. (The Registration Approval Workflow, discussed later, generates an approval task for each registration. Each approval task has a link to the Registration Approval page.) The HTTP request initiates the Page_Load handler. It validates the request and calculates the fields that are used in the ASPX page. The page load process is an example of how to programmatically query for items in a SharePoint list using a task list as an example.

The following sections explain the page load process by examining the methods that are called. The calls occur in the following order:

  • RegistrationApproval.Page_Load. IIS invokes the Page_Load method of the RegistrationApproval class when it receives the initial HTTP request.
  • RegistrationApproval.RenderView. This is a helper method that invokes the presentation layer.
  • RegistrationApprovalPresenter.RenderRegApprovalView. This method validates the registration approval context and calculates the values needed to display the page.
  • RegistrationApprovalPresenter.GetTaskAndRegistration. This method looks up the Registrations list item associated with the task ID given as part of the request.
  • RegistrationApprovalTaskRepository.Get. This method retrieves a RegistrationApprovalTask item from the RegistrationApprovalTasks SharePoint list.
  • RegistrationRepository.Get. This method retrieves a Registration from the Registrations SharePoint list.

The following sections describe each of these methods.

The Page_Load Method

This is the code for the Page_Load method that is invoked by ASP.NET. The code is located in RegistrationApproval.aspx.cs located in the Contoso.TrainingManagement.Web project.

[SharePointPermission(SecurityAction.LinkDemand, ObjectModel = true)]        
protected void Page_Load(object sender, EventArgs e)
{
    Page.Validate();
    if ( !Page.IsPostBack || !Page.IsValid )
    {
        string sourceUrl = String.Empty;
        if ( Request.QueryString["Source"] != null )
        {
            sourceUrl = Request.QueryString["Source"];
        }

        RenderView(SPContext.Current.Web, Request.Params["ID"], sourceUrl);
    }
}

[SharePointPermission(SecurityAction.LinkDemand, ObjectModel = true)]
private void RenderView(SPWeb web, string taskID, string sourceUrl)
{
    RegistrationApprovalPresenter presenter = 
                                  new RegistrationApprovalPresenter(this);
    bool success = presenter.RenderRegApprovalView(web, taskID);            

    ContentMessage.Text = ContentMessage.Text.Replace("\r\n", "<br />");

    if ( success )
    {
        ViewState[taskIdViewStateKey] = taskID;
        if ( sourceUrl == String.Empty )
        {
            sourceUrl = String.Format("{0}/{1}", web.Url, managerDashboardPageFileName);
        }
        ViewState[sourceUrlViewStateKey] = sourceUrl;

        Status.DataBind();
    }
}

The RegistrationApproval.aspx page's Page_Load handler gets information about the execution context from the following two sources:

  • The ASP.NET Request class. The Request class gives access to the parameters passed in as part of the HTTP request. The application uses the QueryString method to extract the ID of the task that is being processed.
  • The SharePoint SPContext class. The SPContext class is a SharePoint class that provides information about the run-time context of the SharePoint application. The SPContext.Current property contains an object that provides information about the SharePoint context that exists when the page loads. The Web property of this context object gives the current SharePoint Web site. The type of the Web site is SPWeb.

Note

The SPWeb object that is returned by the SPContext.Current property represents the current SharePoint site. This object contains methods and properties to access the users, lists, and other content elements of the SharePoint application. For more information, see SPWeb Class (Microsoft.SharePoint) on MSDN.

The Page_Load method invokes a helper method named RenderView. It calls into the next layer of the Training Management application. This layer is implemented by the RegistrationApprovalPresenter class.

Rendering the Registration Approval View

The RenderRegApprovalView method of the RegistrationApprovalPresenter class validates the registration context and calculates the values needed to display the form shown at the beginning of the Registration Approval Use Case. The RenderRegApprovalView method is invoked by the RegistrationApproval class as part of the page load process.

The RenderRegApprovalView method calls a private helper method named GetTaskAndRegistration. This method checks to see if the ID of the task that is one of the HTTP parameters is valid. It also validates the registration that is associated with this task. If all the conditions are met, the manager approval form displays.

The following is the code for the GetTaskAndRegistration method. It is located in the RegistrationApprovalPresenter.cs file.

private bool GetTaskAndRegistration(SPWeb web, IRegistrationApprovalView view, string taskID, out Registration registration)
{
    IRegistrationApprovalTaskRepository registrationApprovalTaskRepository = ServiceLocator.GetInstance().Get<IRegistrationApprovalTaskRepository>();
    RegistrationApprovalTask registrationApprovalTask = null;
    if ( !String.IsNullOrEmpty(taskID) )
    {
        int queryID;
        if ( int.TryParse(taskID, out queryID) )
        {
            registrationApprovalTask = registrationApprovalTaskRepository.Get(queryID, web);
        }
    }

    if ( registrationApprovalTask == null )
    {
        view.Message = "The Approval Task selected is not valid.";
        registration = null;
        return false;
    }

    IRegistrationRepository registrationRepository = ServiceLocator.GetInstance().Get<IRegistrationRepository>();
    int registrationID = registrationApprovalTask.WorkflowItemId;
    registration = registrationRepository.Get(registrationID, web);
    if ( registration == null )
    {
        view.Message = "The Registration associated with the selected Approval Task is not valid.";
        return false;
    }

    return true;
}

This method uses the service locator to acquire instances of the RegistrationApprovalTaskRepository and the RegistrationRepository. Using the taskID parameter, the RegistrationApprovalTaskRepository instance is queried for a RegistrationApprovalTask item. If an item is found, the RegistrationApprovalTask's WorkflowItemId property is then used to query the RegistrationRepository. The WorkflowItemId property provides the link between the RegistrationApprovalTask and the related registration.

Retired Content

This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This page may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.

Footer image

To provide feedback, get assistance, or download additional, please visit the SharePoint Guidance Community Web site.

Copyright © 2008 by Microsoft Corporation. All rights reserved.