Link to home
Start Free TrialLog in
Avatar of paulheinisch
paulheinisch

asked on

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
Avatar of Thogek
Thogek
Flag of United States of America image

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
Avatar of Adrian Sluijters
could you elaborate as to which error you are getting?
which IDE are you using, Visual Studio or none..?
Avatar of paulheinisch
paulheinisch

ASKER

I'm using VS 2002. When I try to open the page...nothing happens...no displaying of the message...
and what version of .NET framework..? 1.0 or 1.1..?
also post everything including codebehind
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?
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>
ASKER CERTIFIED SOLUTION
Avatar of Thogek
Thogek
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
Thanks guys - it worked - setting AutoEventWireup = true - worked! Thanks.
I think you accepted the wrong answer then...
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?
don't worry about it paul... I'm glad you undestood the explanation that's all that matters, but be careful next time  :)
the only problem is that this question might be somehow missleading for others who will have a same problem
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.
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.

https://www.experts-exchange.com/Community_Support/
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
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>
and you mentioned "public void OnLoad()", it belongs to C# not VB
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.
> 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.