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
Solved

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

Posted on 2007-11-27
9
546 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
  • 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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

Question has a verified solution.

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

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
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…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

839 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