Page_Load not loading in a page that has a master page and codebehind

I am using 2.

I have a login.aspx page that has a master page and uses codebehind.

If I put a Page_Load function within my login.aspx page without using codebehind, it works and runs the Page_Load. But if I move the PageLoad to the codebehind, it no longer runs the Page_Load.

I am using debug to step through and it totally does not hit it when I open a page. It does hit the Login1_LoggingIn function after I submit to log in, but not the Page_Load.

Here is what I have:

' there are no Imports....

Partial Class LoginClass
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)

My login.aspx page has this in the @ Page directive:

Also, I have tried this with 3 other files with Page_Loads, different files, and none of them load the Page_Load in the codebehind.

I have also tried it with Page_PreInit

Starr DuskkASP.NET VB.NET DeveloperAsked:
Who is Participating?
nisarkhanConnect With a Mentor Commented:
AutoEventWireup is true for a C# web form, and false for a VB.NET web form

it talks in great detail about AutoEventWireup

in your .aspx  you should have CodeFile="Default.aspx.cs"

for an example:

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" Title="Generic GridView Delete" %>

Starr DuskkASP.NET VB.NET DeveloperAuthor Commented:
I do. I didn't list the entire @page directive. I only indicated that I had included the Inherits in there...

<%@ Page Language="VB" MasterPageFile="~/site.master" AutoEventWireup="false"
    CodeFile="Login.aspx.vb" Inherits="LoginClass" Title="Log In" %>
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

paste the login and master aspx code to see.
Starr DuskkASP.NET VB.NET DeveloperAuthor Commented:
Master Page
<%@ Master Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<script runat="server">
<html xmlns="" >
<head runat="server">
    <title>Untitled Page</title>
    <form id="form1" runat="server">
        <asp:contentplaceholder id="ContentPlaceHolder1" runat="server">

Open in new window

Starr DuskkASP.NET VB.NET DeveloperAuthor Commented:
test page:
<%@ Page Language="VB" MasterPageFile="~/site1.master" AutoEventWireup="false" CodeFile="CookieTest.aspx.vb" Inherits="CookieTest" title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
        <asp:Button ID="Button1" runat="server" Text="Display Cookies" /> 
        <br />
        <asp:Label ID="Label1" runat="server" Text="Label1 Unloaded"></asp:Label><br />
        <hr />
        <asp:Label ID="Label2" runat="server" Text="Label2 Unloaded"></asp:Label>

Open in new window

Starr DuskkASP.NET VB.NET DeveloperAuthor Commented:
Oh. I figured it out. I had:


I set it to true and it runs...

But I had wanted it false, as it says in an article somewhere:

turn off AutoEventWireup for better server performance

I'll have to find out to set it to false and get the Page_Load to load.
if you read the link which i posted it gives you how to execute the page_load event without AutoEventWireup= false

here is the sample:

public partial class _Default : Page
   public _Default() // ctor
      Load += new EventHandler(Page_Load);
      PreInit += new EventHandler(Page_PreInit);        

    protected void Page_Load(object sender, EventArgs e)
       // ...

   protected void Page_PreInit(object sender, EventArgs e)
      // ...
Starr DuskkASP.NET VB.NET DeveloperAuthor Commented:
This is what I needed for VB:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

Thanks for the URL!

(man, what a mess when I have to do a C# app in the future. LOL!)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.