Page_Load is not executed in codebehind

Discussion in 'ASP .Net' started by ericw3@gmail.com, Feb 3, 2006.

  1. Guest

    I am testing the code snippets of John Peterson (
    http://www.asp101.com/articles/john/codebehindnovs/default.asp ).

    I have WebForm2.vb as follows:

    Public Class WebForm2
    Inherits System.Web.UI.Page
    Protected WithEvents Button1 As System.Web.UI.WebControls.Button
    Protected WithEvents Label1 As System.Web.UI.WebControls.Label

    Private Sub Page_Load(sender As System.Object, e As System.EventArgs)
    If Not Page.IsPostBack Then
    Response.Write("Yeah, I got you!")
    end If
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles Button1.Click
    Response.Write("Aha, there you are!")
    Label1.Text = "I was clicked at: " & System.DateTime.Now

    End Sub
    End Class

    And I have WebForm2.aspx as follows:

    <%@ Page Language="vb" AutoEventWireup="false"
    Src="WebForm2.vb" Inherits="WebForm2"%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

    <html>
    <head>
    <title>WebForm2 Code-Behind Test</title>
    </head>
    <body>
    <form id="Form1" method="post" runat="server">
    <asp:Button id="Button1" runat="server" Text="Button">
    </asp:Button>
    <br />
    <br />
    <asp:Label id="Label1" runat="server">Label</asp:Label>
    </form>
    </body>
    </html>

    When I check out WebForm2.aspx from the browser, I noticed that the Sub
    Page_Load is not executed. The Sub Button1_Click is executed upon
    click.

    If I put the subs in WebForm2.aspx and of course make minor changes
    accordingly, the Page_Load Sub gets executed when I check out
    WebForm2.aspx from the browser.

    What is going on? Can anyone please teach me? Thanks.
    , Feb 3, 2006
    #1
    1. Advertising

  2. Guest

    I got it, I need the suffix Handles MyBase.Load


    wrote:
    > I am testing the code snippets of John Peterson (
    > http://www.asp101.com/articles/john/codebehindnovs/default.asp ).
    >
    > I have WebForm2.vb as follows:
    >
    > Public Class WebForm2
    > Inherits System.Web.UI.Page
    > Protected WithEvents Button1 As System.Web.UI.WebControls.Button
    > Protected WithEvents Label1 As System.Web.UI.WebControls.Label
    >
    > Private Sub Page_Load(sender As System.Object, e As System.EventArgs)
    > If Not Page.IsPostBack Then
    > Response.Write("Yeah, I got you!")
    > end If
    > End Sub
    >
    > Private Sub Button1_Click(ByVal sender As System.Object, _
    > ByVal e As System.EventArgs) Handles Button1.Click
    > Response.Write("Aha, there you are!")
    > Label1.Text = "I was clicked at: " & System.DateTime.Now
    >
    > End Sub
    > End Class
    >
    > And I have WebForm2.aspx as follows:
    >
    > <%@ Page Language="vb" AutoEventWireup="false"
    > Src="WebForm2.vb" Inherits="WebForm2"%>
    > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    >
    > <html>
    > <head>
    > <title>WebForm2 Code-Behind Test</title>
    > </head>
    > <body>
    > <form id="Form1" method="post" runat="server">
    > <asp:Button id="Button1" runat="server" Text="Button">
    > </asp:Button>
    > <br />
    > <br />
    > <asp:Label id="Label1" runat="server">Label</asp:Label>
    > </form>
    > </body>
    > </html>
    >
    > When I check out WebForm2.aspx from the browser, I noticed that the Sub
    > Page_Load is not executed. The Sub Button1_Click is executed upon
    > click.
    >
    > If I put the subs in WebForm2.aspx and of course make minor changes
    > accordingly, the Page_Load Sub gets executed when I check out
    > WebForm2.aspx from the browser.
    >
    > What is going on? Can anyone please teach me? Thanks.
    , Feb 3, 2006
    #2
    1. Advertising

  3. ThunderMusic Guest

    that or the following line in "InitializeComponent" :

    this.Load += new System.EventHandler(this.Page_Load);

    the same pattern (line above in InitializeComponent") will allow you to
    handle many other events along the way.

    I hope it helps

    ThunderMusic

    <> wrote in message
    news:...
    >I got it, I need the suffix Handles MyBase.Load
    >
    >
    > wrote:
    >> I am testing the code snippets of John Peterson (
    >> http://www.asp101.com/articles/john/codebehindnovs/default.asp ).
    >>
    >> I have WebForm2.vb as follows:
    >>
    >> Public Class WebForm2
    >> Inherits System.Web.UI.Page
    >> Protected WithEvents Button1 As System.Web.UI.WebControls.Button
    >> Protected WithEvents Label1 As System.Web.UI.WebControls.Label
    >>
    >> Private Sub Page_Load(sender As System.Object, e As System.EventArgs)
    >> If Not Page.IsPostBack Then
    >> Response.Write("Yeah, I got you!")
    >> end If
    >> End Sub
    >>
    >> Private Sub Button1_Click(ByVal sender As System.Object, _
    >> ByVal e As System.EventArgs) Handles Button1.Click
    >> Response.Write("Aha, there you are!")
    >> Label1.Text = "I was clicked at: " & System.DateTime.Now
    >>
    >> End Sub
    >> End Class
    >>
    >> And I have WebForm2.aspx as follows:
    >>
    >> <%@ Page Language="vb" AutoEventWireup="false"
    >> Src="WebForm2.vb" Inherits="WebForm2"%>
    >> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    >>
    >> <html>
    >> <head>
    >> <title>WebForm2 Code-Behind Test</title>
    >> </head>
    >> <body>
    >> <form id="Form1" method="post" runat="server">
    >> <asp:Button id="Button1" runat="server" Text="Button">
    >> </asp:Button>
    >> <br />
    >> <br />
    >> <asp:Label id="Label1" runat="server">Label</asp:Label>
    >> </form>
    >> </body>
    >> </html>
    >>
    >> When I check out WebForm2.aspx from the browser, I noticed that the Sub
    >> Page_Load is not executed. The Sub Button1_Click is executed upon
    >> click.
    >>
    >> If I put the subs in WebForm2.aspx and of course make minor changes
    >> accordingly, the Page_Load Sub gets executed when I check out
    >> WebForm2.aspx from the browser.
    >>
    >> What is going on? Can anyone please teach me? Thanks.

    >
    ThunderMusic, Feb 3, 2006
    #3
  4. Terry Burns Guest

    He's writing in vb.net not c#



    --
    Terry Burns
    http://TrainingOn.net
    "ThunderMusic" <NOdanlatSPAM@hotmaildotcom> wrote in message
    news:...
    > that or the following line in "InitializeComponent" :
    >
    > this.Load += new System.EventHandler(this.Page_Load);
    >
    > the same pattern (line above in InitializeComponent") will allow you to
    > handle many other events along the way.
    >
    > I hope it helps
    >
    > ThunderMusic
    >
    > <> wrote in message
    > news:...
    >>I got it, I need the suffix Handles MyBase.Load
    >>
    >>
    >> wrote:
    >>> I am testing the code snippets of John Peterson (
    >>> http://www.asp101.com/articles/john/codebehindnovs/default.asp ).
    >>>
    >>> I have WebForm2.vb as follows:
    >>>
    >>> Public Class WebForm2
    >>> Inherits System.Web.UI.Page
    >>> Protected WithEvents Button1 As System.Web.UI.WebControls.Button
    >>> Protected WithEvents Label1 As System.Web.UI.WebControls.Label
    >>>
    >>> Private Sub Page_Load(sender As System.Object, e As System.EventArgs)
    >>> If Not Page.IsPostBack Then
    >>> Response.Write("Yeah, I got you!")
    >>> end If
    >>> End Sub
    >>>
    >>> Private Sub Button1_Click(ByVal sender As System.Object, _
    >>> ByVal e As System.EventArgs) Handles Button1.Click
    >>> Response.Write("Aha, there you are!")
    >>> Label1.Text = "I was clicked at: " & System.DateTime.Now
    >>>
    >>> End Sub
    >>> End Class
    >>>
    >>> And I have WebForm2.aspx as follows:
    >>>
    >>> <%@ Page Language="vb" AutoEventWireup="false"
    >>> Src="WebForm2.vb" Inherits="WebForm2"%>
    >>> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    >>>
    >>> <html>
    >>> <head>
    >>> <title>WebForm2 Code-Behind Test</title>
    >>> </head>
    >>> <body>
    >>> <form id="Form1" method="post" runat="server">
    >>> <asp:Button id="Button1" runat="server" Text="Button">
    >>> </asp:Button>
    >>> <br />
    >>> <br />
    >>> <asp:Label id="Label1" runat="server">Label</asp:Label>
    >>> </form>
    >>> </body>
    >>> </html>
    >>>
    >>> When I check out WebForm2.aspx from the browser, I noticed that the Sub
    >>> Page_Load is not executed. The Sub Button1_Click is executed upon
    >>> click.
    >>>
    >>> If I put the subs in WebForm2.aspx and of course make minor changes
    >>> accordingly, the Page_Load Sub gets executed when I check out
    >>> WebForm2.aspx from the browser.
    >>>
    >>> What is going on? Can anyone please teach me? Thanks.

    >>

    >
    >
    Terry Burns, Feb 3, 2006
    #4
    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. =?Utf-8?B?TWFnZXNo?=
    Replies:
    0
    Views:
    357
    =?Utf-8?B?TWFnZXNo?=
    Aug 25, 2004
  2. =?Utf-8?B?RXJpayBKZW5zZW4=?=

    CodeBehind But Not Postback - Page_Load fires twice

    =?Utf-8?B?RXJpayBKZW5zZW4=?=, Jul 19, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    3,299
    =?Utf-8?B?RXJpayBKZW5zZW4=?=
    Jul 21, 2005
  3. Richard Lionheart

    Page_Load(...) not executed in MainWebForm.aspx

    Richard Lionheart, Oct 13, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    544
    Richard Lionheart
    Oct 15, 2005
  4. GaryDean

    CodeBehind File not getting executed

    GaryDean, Dec 24, 2005, in forum: ASP .Net
    Replies:
    5
    Views:
    438
    Karl Seguin
    Dec 24, 2005
  5. Jeff

    Page_Load not executed

    Jeff, May 4, 2009, in forum: ASP .Net
    Replies:
    1
    Views:
    459
    Cowboy \(Gregory A. Beamer\)
    May 4, 2009
Loading...

Share This Page