Wrox Programmer Forums
|
ASP.NET 1.1 As of 10/6/2005, this forum is locked as part of the reorganization described here: http://p2p.wrox.com/topic.asp?TOPIC_ID=35394. No posts have been deleted. Open ongoing discussions from the last week have been moved to either ASP.NET 1.0 and 1.1 Beginners http://p2p.wrox.com/asp-net-1-0-1-1-basics-60/ or ASP.NET 1.0 and 1.1 Professional. http://p2p.wrox.com/forum.asp?FORUM_ID=50. See my sticky post inside for more.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.1 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 29th, 2004, 04:37 AM
Friend of Wrox
 
Join Date: Jun 2004
Posts: 245
Thanks: 0
Thanked 0 Times in 0 Posts
Default Page_Load resets

I want:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)

But when I save and close the solution, Page_Load resets to:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

How can I get VS.Net to not reset and add Handles MyBase.Load to my Page_Load?



 
Old September 29th, 2004, 09:52 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hello,

Why don't you want Handles MyBase.Load there? If you don't have it, the Page_Load doesn't run! That is how it wires the event up.

Brian
 
Old September 30th, 2004, 02:07 AM
Friend of Wrox
 
Join Date: Jun 2004
Posts: 245
Thanks: 0
Thanked 0 Times in 0 Posts
Default

bmains,
I am overriding the MyBase.Load with Custom Base Page Load class. I am implementing context.user.identity from a Custom base page load class. So don't need Handles MyBase.Load as part of Sub Page_Load. How do I get it not to reset itself. This is example from Wrox book.

I am using:
 'This call is required by the Web Form Designer.
        <System.Diagnostics.DebuggerStepThrough()> _
        Private Sub InitializeComponent()
            AddHandler Me.Load, AddressOf Page_Load
        End Sub

 
Old September 30th, 2004, 07:28 AM
Authorized User
 
Join Date: Jul 2004
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Default

If you chose to override the OnLoad() method of the page and don't want the Page_Load handler to do anything then leave it empty! These 2 ways to "do something on page load" are not mutually exclusive so even if the IDE add the handler, don't do anything in it.



 
Old September 30th, 2004, 06:21 PM
Friend of Wrox
 
Join Date: Jun 2004
Posts: 245
Thanks: 0
Thanked 0 Times in 0 Posts
Default

cfouquet
I did left Page_Load out but VS.Net puts Page_Load in automatically. I need VS.Net to not reset Page_Load.

 
Old September 30th, 2004, 09:03 PM
Authorized User
 
Join Date: Jul 2004
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I am not sure anymore what you are trying to do..
However let the IDE wire it up. The delegates are cumulative so it will not hurt anything. If you want us to help you we need to see more code. You talked about overriding MyBase.Load. Are you talking about the OnLoad() or the Load event?

 
Old September 30th, 2004, 09:13 PM
Friend of Wrox
 
Join Date: Jun 2004
Posts: 245
Thanks: 0
Thanked 0 Times in 0 Posts
Default

cfouquet
My parent Custom Base Page_Load code works fine. My child Handles MyBase.Load is not needed so I delete it. But when I recompile or save and restart I get Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Isn't there an option in VS.Net configuration to turn off this automatic reset of Handles MyBase.Load???


Here is the correct code:

Protected Overrides Sub OnInit(ByVal e As EventArgs)
            MyBase.OnInit(e)
            InitializeComponent()
        End Sub


        'This call is required by the Web Form Designer.
        <System.Diagnostics.DebuggerStepThrough()> _
        Private Sub InitializeComponent()
            AddHandler Me.Load, AddressOf Page_Load
        End Sub


Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)

            If Not Page.IsPostBack Then

                'do something
            End If

        End Sub


---------------------------------------------------------------------------------------

 
Old October 3rd, 2004, 12:11 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Quote:
quote:Originally posted by bekim
Isn't there an option in VS.Net configuration to turn off this automatic reset of Handles MyBase.Load???
NO!!

It doesn't matter if VS puts that back in because
A) This:

Private Sub InitializeComponent()
   AddHandler Me.Load, AddressOf Page_Load
End Sub
Private Sub Page_Load(...)
   ...
End Sub

Is the same as this:

Private Sub InitializeComponent()
End Sub
Private Sub Page_Load(...) Handles MyBase.Load
   ...
End Sub

B) No matter how many methods you have handling an event, they will all run...

Private Sub Page_Load1(...) Handles MyBase.Load
End Sub
Private Sub Page_Load2(...) Handles MyBase.Load
End Sub
Private Sub Page_Load3(...) Handles MyBase.Load
End Sub
Private Sub Page_Load4(...) Handles MyBase.Load
End Sub

SO... as has been stated, just let VS put that empty handler in there and don't put anything in it. It's pretty simple.


If you are so annoyed with what visual studio is doing to your code, don't use it! You can write all your code in any text editor you like and compile it all with the complimentary compilers provided along with the .NET framework and relieve yourself from the horribly forceful hands of visual studio.

One thing you could try is renaming the method. Seeing as Visual Studio is most likely seeing the name "Page_Load" and assuming you want that tied to the Page.Load event you might try changing the name to something less obvious to VS. If visual studio is seeing the add handler assignment and rewriting it that way, then you are probably out of luck. Of course, just switching to C# would eliminate this problem altogether because there is no "handles" keyword.
 
Old October 4th, 2004, 07:26 PM
Friend of Wrox
 
Join Date: Jun 2004
Posts: 245
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello planoie

when Private Sub Page_Load .... has Handles MyBase.Load VS.NET doesn't run. That is why this is such a problem.
I thought there was a configuration setting in VS.NET to turn it off but I guess not. Thanks for all your input.


 
Old October 5th, 2004, 07:27 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Did you remove: AddHandler Me.Load, AddressOf Page_Load when you added the Handles MyBase.Load?

If so, then you got a different issue? Is AutoEventWireup set to false?

Brian





Similar Threads
Thread Thread Starter Forum Replies Last Post
DropDownList resets itself (ASP.NET 2.0 AJAX) aisa ASP.NET 2.0 Basics 0 June 11th, 2008 06:12 PM
Accesing ChildNode resets index danblack101 XML 3 May 21st, 2007 03:59 PM
restarting MySQL service resets all my privileges crmpicco MySQL 0 January 27th, 2006 11:33 AM
Page_Load not working! New2ASPnet General .NET 6 July 28th, 2004 01:53 PM
forcing a page_load ? Rashe ASP.NET 1.0 and 1.1 Basics 2 February 16th, 2004 10:53 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.