开发者

Data used by several usercontrols

I have a page with several different usercontrols. All of them run the following code:

var member = System.Web.Security.Membership.GetUser();
MemberProfile mp = MemberProfile.GetUserProfile(member.UserName);
string affilID = mp.GetPropertyValue("aID").ToString();

I would like to get this value once and save it for use with all the controls. I'm not sure where in the life cycle I need to do this to insure it is accessible to all the contr开发者_如何学编程ols when they are being rendered. Any suggestions?

Thank you!


Why not do it in the Page_Load event with Session? Maybe something like this (C#):

MembershipUser member;
MemberProfile mp;
string affilID; 

protected void Page_Load(object sender, EventArgs e)
{

    if (Session["member"] != null)
    {
        member = (MembershipUser)Session["member"];
    }
    else
    {
        member = System.Web.Security.Membership.GetUser();
    }

    if (Session["mp"] != null)
    {
        mp = (MemberProfile)Session["mp"];
    }
    else
    {
        mp = MemberProfile.GetUserProfile(member.UserName);
    }

    if (Session["affilID"] != null)
    {
        affilID = (string)Session["affilID"];
    }
    else
    {
        affilID = mp.GetPropertyValue("aID").ToString();
    }
}


If it's all on the same page, as long as it's outside of a subroutine you should be able to use it within any subroutine. Or am I missing something?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜