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.