Page_load will not run

I'm new to asp.net and I'm trying to use page_load and for whatever reason its not working...???  Any reason as why? The code is very easy stuff:

for now its just this (for testing )

<script runat="server" language="vb">
                  Sub Page_Load(Sender As Object, E As EventArgs)
                        If Not IsPostback Then
                              Response.Write("This code was executed")
                        End if
                        

                  End Sub
            </script>

And it will not run...

Thanks
LVL 1
paulheinischAsked:
Who is Participating?
 
ThogekConnect With a Mentor Commented:
Note that using AutoEventWireup adds the plumbing for the handling of several different page events, and, if you're not using all of these events, may affect overall performance (although the extent of this effect may or may not be noticable, depending on your situation).

See http://support.microsoft.com/default.aspx?scid=kb;EN-US;324151#7
0
 
ThogekCommented:
Try changing

    Sub Page_Load(Sender As Object, E As EventArgs)

to

    Sub Page_Load(Sender As Object, E As EventArgs) Handles MyBase.Load

More about VB.NET event handler methods at http://msdn.microsoft.com/library/en-us/vbls7/html/vblrfvbspec7_1_8.asp
0
 
pegasysCommented:
could you elaborate as to which error you are getting?
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
davidlars99Commented:
which IDE are you using, Visual Studio or none..?
0
 
paulheinischAuthor Commented:
I'm using VS 2002. When I try to open the page...nothing happens...no displaying of the message...
0
 
davidlars99Commented:
and what version of .NET framework..? 1.0 or 1.1..?
0
 
davidlars99Commented:
also post everything including codebehind
0
 
paulheinischAuthor Commented:
Net 1.1   Ok here is where I may be a little ignorant...I don't have any additional code behind it...shoud I ? And if so, where would it be?
0
 
davidlars99Commented:
try this first

<%@ Page Language="vb" AutoEventWireup="true"%>
<HTML>
<HEAD>
<Script Language="VB" Runat="Server">

Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
      lblmsg.Text="hello there..!"
End Sub

</Script>
</HEAD>
<BODY>
<form id="form1" runat="server">
      <asp:label id="lblmsg" runat="server" />
</form>
</BODY>
</HTML>
0
 
davidlars99Commented:
Thogek, if you're not using codebehind then autoeventwireup is better be set to false otherwise true, what you said is true when you're using visual studio and codebehind
0
 
paulheinischAuthor Commented:
Thanks guys - it worked - setting AutoEventWireup = true - worked! Thanks.
0
 
davidlars99Commented:
I think you accepted the wrong answer then...
0
 
paulheinischAuthor Commented:
THis is my second time using this system, so I am sorry if I accepted the worng answer - is there something I can do to fix this?
0
 
davidlars99Commented:
don't worry about it paul... I'm glad you undestood the explanation that's all that matters, but be careful next time  :)
0
 
davidlars99Commented:
the only problem is that this question might be somehow missleading for others who will have a same problem
0
 
paulheinischAuthor Commented:
Ok...I will make sure to be more careful - thanks for all your help with this and the proper way to use this web site; so far, this has been a great resource for me. Thanks again.
0
 
ThogekCommented:
paul,
If you accepted the wrong answer -- which appears to be the case, as my suggestion was way up top on the list, and davidlars99 was the one who suggested AutoEventWireup -- you can request in the Community Support area to have a question re-opened so that you can accept the correct answer.

http://www.experts-exchange.com/Community_Support/
0
 
ThogekCommented:
davidlars99,
What I posted is not dependant upon whether your code is in the ASPX file or within a code-behind -- although if you're not in a situation where the level of performance is that finely critical (and most aren't), you probably won't notice the difference either way.

"The AutoEventWireup attribute requires the ASP.NET page framework to make a call to the CreateDelegate function for every ASP.NET Web Form page."
http://support.microsoft.com/default.aspx?scid=kb;EN-US;324151#7

"Instead of relying on autoeventwireup, override the events from Page.  For example, instead of writing a Page_Load() method, try overloading the public void OnLoad() method.  This allows the run time from having to do a CreateDelegate() for every page."
http://msdn.microsoft.com/library/en-us/dndotnet/html/dotnetperftips.asp
0
 
davidlars99Commented:
your articles assume that you are using codebehind technique and of course preferred way is to set autoeventwireup to false and explicitly use event handlers like so, this example doesn't use codebehind but inherits from "Page" class and uses "Handlers" (almost as same as codebehind technique), you must be aware of setting "autoeventwireup" to true when using codebehind because each declared page event might fire twice and screw up the whole thing, than you spend all day trying to find out what went wrong...  :)



<%@ Page Language="VB" Debug="true" autoeventwireup="false" Inherits="System.Web.UI.Page" %>
<HTML>
<HEAD>
<Script Language="VB" Runat="Server">

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
     lblmsg.Text="hello there..!"
End Sub

Protected Sub button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles button1.Click
     lblmsg.Text="you clicked " & sender.id.ToString()
End Sub

</Script>
</HEAD>
<BODY>
<form id="form1" runat="server">
     <asp:label id="lblmsg" runat="server" />
     <br>
     <asp:button id="button1" text="Click Me" runat="server" />
</form>
</BODY>
</HTML>
0
 
davidlars99Commented:
and you mentioned "public void OnLoad()", it belongs to C# not VB
0
 
ThogekCommented:
Actually, OnLoad belongs to Page (inherited from Control).  The syntax used in the quote I cited was C#, but the method still exists if you're using VB.
0
 
ThogekCommented:
> this example doesn't use codebehind but inherits from "Page" class and uses "Handlers"
> (almost as same as codebehind technique),

Almost exactly the same, as in codebehind, your page inherits from your code-behind class which inherits from Page, so you're page's relationship with the parent Page class is still there.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.