Solved

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

Posted on 2007-11-27
9
558 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:Starr Duskk
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2

Author Comment

by:Starr Duskk
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Author Comment

by:Starr Duskk
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
 
LVL 2

Author Comment

by:Starr Duskk
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 2

Author Comment

by:Starr Duskk
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 2

Author Comment

by:Starr Duskk
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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

717 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