頁面加載時,會去加載Page_Load事件,然后如果點擊頁面上的按鈕,依然是先執行Page_Load,然后執行btnPreview_Click事件,現在有一個問題,就是點擊按鈕后,Page_Load事件檢測到Session為null時,可否直接返回到指定頁,而不去加載btnPreview_Click事件。
??? protected void Page_Load(object sender, EventArgs e)??? {??????? if (Session["UserID"] == null)??????? {??????????? Response.Write("<script>parent.location.href='Timeout.aspx';<" + "/script>");??????????? return;??????? }
??? }
??? protected void btnPreview_Click(object sender, EventArgs e)??? {??????? CrystalReportViewer1.Visible = true;??????? Display();??? }
??? private void Display()
??? {
????????? Response.Write(Session["UserID"].ToString());
????? }
1 回答

江戶川亂折騰
TA貢獻1851條經驗 獲得超5個贊
if(Session["UserID"] == null)
??????? {
?
Response.Redirect("target.aspx");
}
就OK
- 1 回答
- 0 關注
- 462 瀏覽
添加回答
舉報
0/150
提交
取消