Solved

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

Posted on 2007-11-27
9
513 Views
Last Modified: 2012-05-05
I am using asp.net 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:
Inherits="LoginClass"

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

0
Comment
Question by:BobCSD
  • 5
  • 4
9 Comments
 
LVL 7

Expert Comment

by:nisarkhan
ID: 20362115
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" %>


0
 
LVL 1

Author Comment

by:BobCSD
ID: 20362142
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" %>
0
 
LVL 7

Expert Comment

by:nisarkhan
ID: 20362148
paste the login and master aspx code to see.
0
 
LVL 1

Author Comment

by:BobCSD
ID: 20362244
Master Page
<%@ Master Language="VB" %>
 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 

<script runat="server">
 

</script>
 

<html xmlns="http://www.w3.org/1999/xhtml" >

<head runat="server">

    <title>Untitled Page</title>

</head>

<body>

    <form id="form1" runat="server">

    <div>

        <asp:contentplaceholder id="ContentPlaceHolder1" runat="server">

        </asp:contentplaceholder>

    </div>

    </form>

</body>

</html>

Open in new window

0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 1

Author Comment

by:BobCSD
ID: 20362248
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">
 

   <div>
 

        <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>

    </div>
 
 

</asp:Content>

Open in new window

0
 
LVL 1

Author Comment

by:BobCSD
ID: 20362254
Oh. I figured it out. I had:

 AutoEventWireup="false"

I set it to true and it runs...
 AutoEventWireup="true"

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.
0
 
LVL 7

Accepted Solution

by:
nisarkhan earned 500 total points
ID: 20362310
AutoEventWireup is true for a C# web form, and false for a VB.NET web form

it talks in great detail about AutoEventWireup

http://odetocode.com/Blogs/scott/archive/2006/02/16/2914.aspx

0
 
LVL 7

Expert Comment

by:nisarkhan
ID: 20362315
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)
   {
      // ...
   }
}
0
 
LVL 1

Author Comment

by:BobCSD
ID: 20362396
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!)
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Using MS Code on my Mac 6 47
crm development 2 39
How can I use this extension method? 8 36
What .NET website keeps me current? 9 33
Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now