开发者

how to programmatically decide which content page to load , on master page load

开发者 https://www.devze.com 2023-04-05 00:08 出处:网络
I have a master page and two content pages with the same ContentPlaceHolderID. Is there a way to specify which content page should be loaded from the Page_Load event of the master page?

I have a master page and two content pages with the same ContentPlaceHolderID. Is there a way to specify which content page should be loaded from the Page_Load event of the master page?

If I watch the value of:

Request.CurrentExecutionFilePath;

I see the path of the first content page.

According to the condition specified below i want to change it to the path of the second content page.

I am looking for a way to load a specific page depending on a check I d开发者_开发知识库o on the Master Page_Load.

If I attempt to redirect to the page from there I get stuck in an endless loop because the master page loads again before the content page and re-does the check and redirects again and again.

// in master page 
protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        if (Request.Cookies["user"] != null)
        {
            HttpCookie cookie = Request.Cookies["user"];
            string name = cookie.Value;
            Response.Redirect("~/hello_page.aspx?UserName=" + name);
        }
    }
}

Thanks in advance.


You could check on page load for the querystring you're including in the redirect. If the querystring is there, then you will have already redirected, so you can skip over the cookie-check-and-redirect block.

0

精彩评论

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