Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Application_PreSendRequestContent is way too late in the page lifecycle to be doing this. The MasterPage has already been executed at this stage.</p> <p>Global.asax is really a place for Application events rather than page specific. Be aware that many of the application events like Application_BeginRequest are called on any request, not just aspx Page requests. Many of these events are fired for every js script, image, css file etc that is requested.</p> <p>Here is a good list of the events in Global.asax: <a href="https://web.archive.org/web/1/http://articles.techrepublic%2ecom%2ecom/5100-10878_11-5771721.html" rel="nofollow noreferrer">https://web.archive.org/web/1/http://articles.techrepublic%2ecom%2ecom/5100-10878_11-5771721.html</a></p> <p>The only place that I know that you can definately change the master page is in the page Page_PreInitevent handler</p> <pre><code>protected void Page_PreInit(object sender, EventArgs e) { this.Page.MasterPageFile = "~/Custom.master"; } </code></pre> <p>Edit: Reading your comments, it sounds to me that you need to derive your pages from a base page which makes the change in one place.</p> <pre><code>using System; namespace TestWebApplication { public class PageBase : System.Web.UI.Page { protected void Page_PreInit(object sender, EventArgs e) { Page.MasterPageFile = "~/Custom.master"; } } } </code></pre> <p>Then alter all of your pages to inherit this instead of System.Web.UI.Page...</p> <pre><code>//public partial class WebForm1 : System.Web.UI.Page public partial class WebForm1 : PageBase { protected void Page_Load(object sender, EventArgs e) { } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload