Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / December 2007

Tip: Looking for answers? Try searching our database.

Subclass web.ui.page

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Arne Garvander - 05 Dec 2007 20:46 GMT
What is the proper way to subclass web.ui.page?
Public Class MyPage
   Inherits System.Web.UI.Page

   Protected Sub Page_Init(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Init
       'MyBase.OnInit(e)
       ViewStateUserKey = Session.SessionID
   End Sub
End Class

When I called OnInit in my base class I got an infinite loop.

Signature

Arne Garvander
Certified Geek
Professional Data Dude

bruce barker - 05 Dec 2007 21:07 GMT
Page_Init is an event fired by OnInit, so when you call OnInt, it calls
Page_Init.
you only need to call base.OnInit if you override OnInit, not if you
register an event handler.

-- bruce (sqlwork.com)

> What is the proper way to subclass web.ui.page?
> Public Class MyPage
[quoted text clipped - 8 lines]
>
> When I called OnInit in my base class I got an infinite loop.
Arne Garvander - 05 Dec 2007 21:13 GMT
Should I override oninit or handle init?
What would be the syntax to override oninit?

Signature

Arne Garvander
Certified Geek
Professional Data Dude

> Page_Init is an event fired by OnInit, so when you call OnInt, it calls
> Page_Init.
[quoted text clipped - 15 lines]
> >
> > When I called OnInit in my base class I got an infinite loop.
Milosz Skalecki [MCAD] - 05 Dec 2007 21:19 GMT
Howdy Arne,

Infinite loop is caused by calling OnInit from the event handler (C#):

protected virtual void OnInit(EventArgs e)
{
  // this raises the vent you're handling through Page_Init
  if (Init != null)
      Init(this, e);
}

which is (simplifying) equivalent to:

protected virtual void OnInit(EventArgs e)
{
  if (Init != null)
  {
     // equivalent to replacing Init with your event handler
     OnInit(e);
  }
}

As you can see, OnInit calls itself causing infinite loop and stack overflow.

You should change it to:
Public Class MyPage
   Inherits System.Web.UI.Page

    Protected Overrides Sub OnInit(ByVal e As System.EventArgs)
       
        MyBase.OnInit(e)
        ViewStateUserKey = Session.SessionID
       
    End Sub

End Class

There's one more thing: could you please explain why you're setting a view
state property on every postback?

Regards
Signature

Milosz

> What is the proper way to subclass web.ui.page?
> Public Class MyPage
[quoted text clipped - 8 lines]
>
> When I called OnInit in my base class I got an infinite loop.
Arne Garvander - 05 Dec 2007 21:25 GMT
Setting the ViewstateUserkey makes hacking more difficult.
http://msdn2.microsoft.com/en-us/library/ms972969.aspx

Signature

Arne Garvander
Certified Geek
Professional Data Dude

> Howdy Arne,
>
[quoted text clipped - 50 lines]
> >
> > When I called OnInit in my base class I got an infinite loop.

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.