views:

161

answers:

4

I put a break point at the protected void Page_Load(object sender, EventArgs e) method of my master page, but when i start the site it does not hit that break point.

Why is the event not firing? I would like to use this event along with others such as the Init event in order to check to see if the session has expired everytime a page loads...

Thanks.

+1  A: 

You might want to try creating a base class of type Page that handles your session check. Leave the master pages for page design. If you have multiple master pages, you would have to duplicate that code in each one, but if your pages inherit from a single base page, your session check logic will be in one place.

MCain
well that sounds good. how do i do that?
kralco626
Create a class "MyCompany.BasePage" of type Page. Add your session check in Load. Then, in your codebehind of each of your pages, change the type from Page to MyCompany.BasePage
MCain
should it be .BasePage.cs? I went to add item and selected "class and called it MySite.BasePage
kralco626
Sure, create a .cs class. Have it inherit System.Web.UI.Page. Implement Page.Page_Load in BasePage. Then inherit BasePage in your other pages.
MCain
I used the following solution: http://www.dreamincode.net/forums/topic/45300-base-page-for-detecting-session-timeout-in-aspnetc%23/ Copy the code at the botttom and have your page inherit SessionState rather than Page
kralco626
+2  A: 

The problem is likely that your .aspx page has not correctly referencing your .master page. Be sure that, at the top of your .aspx page, you have a line similar to the following:

<%@ Page Title="Some Title" Language="C#" MasterPageFile="Main.Master" CodeBehind="MyPage.aspx.cs" Inherits="MyApp.MyPage" %>

Another possible problem is that your .master page isn't referencing the proper (or any) assembly. Be sure that the top line of your .master page is similar to the following:

<%@ Master Language="C#" AutoEventWireup="True" CodeBehind="Main.master.cs" Inherits="MyApp.Main" %>
Byron Sommardahl
Thanks for your answer. Two things. First. My page is deffinatly reference the master page correctly. second, what is the inherits="MyApp.Main" mean? edit: oh and the break point i set it on the master page itself.
kralco626
+1  A: 

A couple of things to check, some of which may be obvious...

  1. Check your child page is calling the correct Master Page.

  2. The Master Page Page_Load executes after the child Page_Load, so make sure you debug through the child page execution first.

  3. Check that you've actually got your Page_Load event wired up if you're using VB.NET.

Damien Dennehy
sorry. should have said i'm using c# so 3 doesn't apply. deff got 1 right. And the website loads up and everything. I use it etc. it should have called the master page Page_load method before then right?
kralco626
A: 

You need to check declaration of page to make sure it refers proper masterpage and masterpage, to make sure that it refers proper inherited class.

Sergey Osypchuk