I have an ASP.NET webpage written in C#. In my master page, I have a <select>
element which allows the user to switch between two different databases. I thought I could just add code to the Master Page Page_Load() method to check if the form containing the select has been submitted, and if so, set some session variables which define what database I'm connecting to.
The problem is, it looks like the Page itself loads before the Master page's Page_Load method because when I submit the form it does update my session variable, but my queries are still looking at the original database. However, if I submit the form twice, it registers.
I'm guessing that the Master Page's Page_Load method MUST fire AFTER the Page's Page_Load method. Is there somewhere I can place my code so it will be triggered on ALL pages but will execute BEFORE the page loads?
All I'm doing is...
if (Request.Form["database"] != null) {
Session["database"] = Request.Form["database"];
}