Why does page_load fire twice when inheriting from a common overridable Page_Load

Discussion in 'ASP .Net' started by bminder, Feb 23, 2004.

  1. bminder

    bminder Guest

    In the asp.net pages below, Common.vb has an overridable Page_Load sub. In
    the consuming page, Two.aspx, the Page_Load sub is inherited, but for some
    reason it (Overrides Sub Page_Load) executes twice.

    In another "regular" asp.net page that inherits only from its own codebehind
    page, the page load only executes once as you'd expect.

    Any ideas why the page_load fires twice in the former example?

    Thanks,

    Brent

    ============
    Common.vb:
    ============
    Imports System
    Imports System.Web.UI
    Imports System.Web.UI.HtmlControls
    Imports System.Web.UI.WebControls

    Public Class Common
    Inherits Page
    Protected WithEvents lblHeader As Label
    Overridable Sub Page_Load(ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles MyBase.Load
    lblHeader.Text = "Overridable common text."
    End Sub
    End Class

    ============
    Two.aspx:
    ============
    <%@ Page Language="vb" AutoEventWireup="false" Codebehind="Common.vb"
    Inherits="MyTest.Common"%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <html>
    <body>
    <form method="post" runat="server">
    <asp:Label Runat=server ID=lblHeader />
    </form>
    <script language=vb runat=server>
    Overrides Sub Page_Load(ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles MyBase.Load
    'mybase.Page_Load(sender, e)
    lblHeader.Text &= "<br>Page TWO Overriding page load<br><a
    href='./one.aspx'>Back to Page One</a>"
    end sub
    </script>
    </body>
    </html>
     
    bminder, Feb 23, 2004
    #1
    1. Advertising

  2. bminder

    nfedin Guest

    Try removing "Handles MyBase.Load" from both Common.vb and Two.aspx

    "bminder" <> wrote in message news:<>...
    > In the asp.net pages below, Common.vb has an overridable Page_Load sub. In
    > the consuming page, Two.aspx, the Page_Load sub is inherited, but for some
    > reason it (Overrides Sub Page_Load) executes twice.
    >
    > In another "regular" asp.net page that inherits only from its own codebehind
    > page, the page load only executes once as you'd expect.
    >
    > Any ideas why the page_load fires twice in the former example?
    >
    > Thanks,
    >
    > Brent
    >
    > ============
    > Common.vb:
    > ============
    > Imports System
    > Imports System.Web.UI
    > Imports System.Web.UI.HtmlControls
    > Imports System.Web.UI.WebControls
    >
    > Public Class Common
    > Inherits Page
    > Protected WithEvents lblHeader As Label
    > Overridable Sub Page_Load(ByVal sender As System.Object, ByVal e As
    > System.EventArgs) Handles MyBase.Load
    > lblHeader.Text = "Overridable common text."
    > End Sub
    > End Class
    >
    > ============
    > Two.aspx:
    > ============
    > <%@ Page Language="vb" AutoEventWireup="false" Codebehind="Common.vb"
    > Inherits="MyTest.Common"%>
    > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    > <html>
    > <body>
    > <form method="post" runat="server">
    > <asp:Label Runat=server ID=lblHeader />
    > </form>
    > <script language=vb runat=server>
    > Overrides Sub Page_Load(ByVal sender As System.Object, ByVal e As
    > System.EventArgs) Handles MyBase.Load
    > 'mybase.Page_Load(sender, e)
    > lblHeader.Text &= "<br>Page TWO Overriding page load<br><a
    > href='./one.aspx'>Back to Page One</a>"
    > end sub
    > </script>
    > </body>
    > </html>
     
    nfedin, Feb 23, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Rashad Rivera

    Why does Application_Start fire twice?

    Rashad Rivera, Apr 26, 2004, in forum: ASP .Net
    Replies:
    5
    Views:
    3,821
    Matt Berther
    May 1, 2004
  2. Duron

    Font.Text overridable?

    Duron, Sep 13, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    338
    Duron
    Sep 14, 2004
  3. Mr. SweatyFinger
    Replies:
    2
    Views:
    2,237
    Smokey Grindel
    Dec 2, 2006
  4. Dilip
    Replies:
    5
    Views:
    411
  5. Jean-Francois Larvoire

    Why does onMouseOver fire twice?

    Jean-Francois Larvoire, Aug 21, 2004, in forum: Javascript
    Replies:
    3
    Views:
    147
    Geir Klemetsen
    Aug 23, 2004
Loading...

Share This Page