Page_Load is not executed in codebehind

E

ericw3

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.
 
T

ThunderMusic

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top