Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2007-11-27
9
Medium Priority
?
567 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

618 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