[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Page_load will not run

Posted on 2005-04-06
22
Medium Priority
?
303 Views
Last Modified: 2012-05-05
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
0
Comment
Question by:paulheinisch
  • 10
  • 6
  • 5
  • +1
22 Comments
 
LVL 15

Expert Comment

by:Thogek
ID: 13724098
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
 
LVL 7

Expert Comment

by:pegasys
ID: 13725123
could you elaborate as to which error you are getting?
0
 
LVL 13

Expert Comment

by:davidlars99
ID: 13726747
which IDE are you using, Visual Studio or none..?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:paulheinisch
ID: 13727364
I'm using VS 2002. When I try to open the page...nothing happens...no displaying of the message...
0
 
LVL 13

Expert Comment

by:davidlars99
ID: 13727400
and what version of .NET framework..? 1.0 or 1.1..?
0
 
LVL 13

Expert Comment

by:davidlars99
ID: 13727410
also post everything including codebehind
0
 
LVL 1

Author Comment

by:paulheinisch
ID: 13727905
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
 
LVL 13

Expert Comment

by:davidlars99
ID: 13728297
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
 
LVL 15

Accepted Solution

by:
Thogek earned 200 total points
ID: 13728918
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
 
LVL 13

Expert Comment

by:davidlars99
ID: 13729128
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
 
LVL 1

Author Comment

by:paulheinisch
ID: 13730521
Thanks guys - it worked - setting AutoEventWireup = true - worked! Thanks.
0
 
LVL 13

Expert Comment

by:davidlars99
ID: 13730536
I think you accepted the wrong answer then...
0
 
LVL 1

Author Comment

by:paulheinisch
ID: 13730869
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
 
LVL 13

Expert Comment

by:davidlars99
ID: 13730931
don't worry about it paul... I'm glad you undestood the explanation that's all that matters, but be careful next time  :)
0
 
LVL 13

Expert Comment

by:davidlars99
ID: 13730939
the only problem is that this question might be somehow missleading for others who will have a same problem
0
 
LVL 1

Author Comment

by:paulheinisch
ID: 13730988
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
 
LVL 15

Expert Comment

by:Thogek
ID: 13732912
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
 
LVL 15

Expert Comment

by:Thogek
ID: 13732926
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
 
LVL 13

Expert Comment

by:davidlars99
ID: 13735434
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
 
LVL 13

Expert Comment

by:davidlars99
ID: 13735441
and you mentioned "public void OnLoad()", it belongs to C# not VB
0
 
LVL 15

Expert Comment

by:Thogek
ID: 13737177
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
 
LVL 15

Expert Comment

by:Thogek
ID: 13737195
> 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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:   The Exchange of informatio…
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question