Removing duplicate calls on an AspNet Page Load by using the MasterPage

This is often something that is never apparent but can improve performance. On the master page, you need to make a call, for example, to get the MembershipUser.

MembershipUser user = Membership.GetUser();

Then on the page you need to do the same so you copy the code again.  This results in two calls. For a current project, this means two WCF calls so there is a significant latency added to page rendering.  A better solution is to make the User public on the master page and then use it (and avoid the second call).

 

On the master page, change it to a self-initializing property (and avoid putting initialization into events like Page_Load)

MembershipUser _User
public MembershipUser User
{
    get
    {
        if (_User == null)
        {
            _User = Membership.GetUser();
        }
        return _User;
    }
}
   and then on the child pages use:

protected void Page_Load(object sender, EventArgs e)
{
    var user = ((MyUserPortal.AppMasters.Default)Master).User;
}

You have eliminated a call with little effort and improved performance.

 

Bottom line, be aware of what is in the Master Page and strive to re-use what is there.

Comments

Popular posts from this blog

Yet once more into the breech (of altered programming logic)

Simple WP7 Mango App for Background Tasks, Toast, and Tiles: Code Explanation

How to convert SVG data to a Png Image file Using InkScape