I'm trying to use my master page's code-behind to display a message to the user after a redirect. Specifically,
public partial class SiteMaster : System.Web.UI.MasterPage
{
protected void Page_Load(object sender, EventArgs e)
{
if (Session["redirect_message"] != null)
{
// put the message in a hidden field for JavaScript to put in an alert()
Session.Remove("redirect_message");
}
}
}
Any page that then wants to show a message can do this:
Session["redirect_message"] = "I've sent you to OtherPage.aspx";
Response.Redirect("~/OtherPage.aspx");
That works the way I want it to...I first get OtherPage.aspx
's Page_Load
event, then I get the master's Page_Load
event. However, I read in many places (like here) that this way of redirecting is not advisable. So, I changed to the recommended way:
Session["redirect_message"] = "I've sent you (nicely this time) to OtherPage.aspx";
Response.Redirect("~/OtherPage.aspx", false); // don't use Response.End()
Context.Application.CompleteRequest();
and unfortunately now my master page's Page_Load
event is being called before OtherPage.aspx
begins loading. I see from this response that there's no good way to stop processing the page (other than to use MVC, which isn't an option for me)--is there a way to at least prevent the master page controls from loading?