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 October 5th, 2004, 09:05 AM
Friend of Wrox
 
Join Date: Jun 2004
Posts: 245
Thanks: 0
Thanked 0 Times in 0 Posts
Default

bmains,
I need the AddHandler Me.Load, AddressOf Page_Load.

When I delete Handles MyBase.Load sometimes VS.Net deletes AddHandler Me.Load, AddressOf Page_Load and adds Handles MyBase.Load.

When I save sometimes it won't reset itself but it usually does. Even when I save and close the solution, some pages with this will reset itself and some won't.

I think when it recompiles itself it resets itself.

Is there a way to shut this reset mode off????

I got this example from a Wrox book. Thank you.

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

Switch to C#. I don't believe you can.
 
Old October 6th, 2004, 06:03 AM
Friend of Wrox
 
Join Date: Jun 2004
Posts: 245
Thanks: 0
Thanked 0 Times in 0 Posts
Default

bmains
thanks for your advice. I will switch to C# in 6months. I just started to learn VB.NET 6 months ago. Thanks.

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

Just out of curiosity, why do you need the AddHandler statement again over the Handles keyword?

And I was kidding about the C#...

Brian
 
Old October 8th, 2004, 03:04 AM
Friend of Wrox
 
Join Date: Jun 2004
Posts: 245
Thanks: 0
Thanked 0 Times in 0 Posts
Default

bmains
I am using AddHandler statment over Handles keyword because all ASPX pages inherits a Base Page. Base Page has Context.User.Identity.IsAuthenticated and Base Page Error to record Server Error to Error.Txt.

This was an example from a Wrox book -- ASP.NET Website Programming Problem-Design-Solution.

I use this with all ASPX pages.

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


Then my Base Page is:

Namespace ThePhile.Web

    Public Class BasePage
        Inherits System.Web.UI.Page


        ' Page Events
        '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        Protected Overrides Sub OnInit(ByVal e As EventArgs)

            MyBase.OnInit(e)
            AddHandler Me.Load, AddressOf BasePage_Load
            AddHandler Me.Error, AddressOf BasePage_Error

        End Sub


        Private Sub BasePage_Load(ByVal sender As Object, ByVal e As EventArgs)

            If Context.User.Identity.IsAuthenticated Then

                If Not (TypeOf context.User Is SitePrincipal) Then



                    Dim newUser As New SitePrincipal(Context.User.Identity.Name)
                    Context.User = newUser

                End If

            End If

        End Sub


        Protected Sub BasePage_Error(ByVal sender As Object, ByVal e As EventArgs)

            Dim currentError As Exception = Server.GetLastError()

            ' Write error to log file if not already done by AppException
            If Not (TypeOf currentError Is AppException) Then
                AppException.LogError(currentError.Message.ToStrin g)
            End If

            ' Show error on screen
            ShowError(currentError)

            ' Clear error so that it does not buble up to Application Level
            Server.ClearError()

        End Sub



        ' Shared Methods
        '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

        Public Shared Sub ShowError(ByVal currentError As Exception)

            Dim context As HttpContext = HttpContext.Current

            context.Response.Write( _
              "<link rel=""stylesheet"" href=""/ThePhileVB/Styles/ThePhile.css"">" & _
              "<h2>Error</h2>" & _
              "An unexpected error has occurred on this page." & _
              "The system administrators have been notified.<br/>" & _
              "<br/><b>The error occurred in:</b>" & _
                "<pre>" & context.Request.Url.ToString & "</pre>" & _
              "<br/><b>Error Message:</b>" & _
                "<pre>" & currentError.Message.ToString & "</pre>" & _
              "<br/><b>Error Stack:</b>" & _
               "<pre>" & currentError.ToString & "</pre>")

        End Sub


    End Class

End Namespace
-------------------------------------------------------------

Is there a better way to do this to avoid my reseting "Handles MyBase.Load" problem?????

 
Old October 8th, 2004, 05:17 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hey,

I can see your situation. But no, there is nothing you can do about it. All you can do is wait until the next version comes out, and forces you to change all of your code! Sorry about that.

Brian
 
Old October 9th, 2004, 06:06 AM
Friend of Wrox
 
Join Date: Jun 2004
Posts: 245
Thanks: 0
Thanked 0 Times in 0 Posts
Default

bmains,
So should I put code in Notepad and manually compile this?
What compiler do I use and where do I get this?

 
Old October 16th, 2004, 04:08 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:I am using AddHandler statment over Handles keyword because all ASPX pages inherits a Base Page. Base Page has Context.User.Identity.IsAuthenticated and Base Page Error to record Server Error to Error.Txt.
Huh?? What does any of that have to do with how the page load method is wired to the event handler (which is what we keep asking you about)?

What part of this do you not understand?:
Quote:
quote:Originally posted by planoie
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
Are you actually experiencing a problem when you use the method that visual studio puts in there and is "resetting", as you put it? I have several applications that have pages that inherit from a basepage class. In fact my latest project has pages that inherit from a chain of about 3 or 4 classes before "System.Web.UI.Page". This doesn't result in any problems with "Handles MyBase.Load" at all from what I've seen.

You can find the compiler in the framework directory which is typically found at "C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322" or something similar. The VB compiler is "vbc.exe".





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.