![](/img/trans.png)
[英]Which event called first? Master Page Page_Load or Content Page Page_Load
[英]how to programmatically decide which content page to load , on master page load
我有一個母版頁和兩個內容頁面具有相同的ContentPlaceHolderID。 有沒有辦法指定應從母版頁的Page_Load
事件加載哪個內容頁面?
如果我看到的價值:
Request.CurrentExecutionFilePath;
我看到了第一個內容頁面的路徑。
根據下面指定的條件,我想將其更改為第二個內容頁面的路徑。
我正在尋找一種方法來加載特定的頁面取決於我在Master Page_Load
上的檢查。
如果我嘗試從那里重定向到頁面,我會陷入無限循環,因為母版頁在內容頁面之前再次加載並重新進行檢查並反復重定向。
// 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);
}
}
}
提前致謝。
您可以檢查頁面加載以查找重定向中包含的查詢字符串。 如果查詢字符串在那里,那么您將已經重定向,因此您可以跳過cookie-check-and-redirect塊。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.