473,378 Members | 1,541 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Subclass web.ui.page

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.

--
Arne Garvander
Certified Geek
Professional Data Dude
Dec 5 '07 #1
4 2958
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)
"Arne Garvander" wrote:
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.

--
Arne Garvander
Certified Geek
Professional Data Dude
Dec 5 '07 #2
Should I override oninit or handle init?
What would be the syntax to override oninit?

--
Arne Garvander
Certified Geek
Professional Data Dude
"bruce barker" wrote:
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)
"Arne Garvander" wrote:
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.

--
Arne Garvander
Certified Geek
Professional Data Dude
Dec 5 '07 #3
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
--
Milosz
"Arne Garvander" wrote:
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.

--
Arne Garvander
Certified Geek
Professional Data Dude
Dec 5 '07 #4
Setting the ViewstateUserkey makes hacking more difficult.
http://msdn2.microsoft.com/en-us/library/ms972969.aspx

--
Arne Garvander
Certified Geek
Professional Data Dude
"Milosz Skalecki [MCAD]" wrote:
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
--
Milosz
"Arne Garvander" wrote:
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.

--
Arne Garvander
Certified Geek
Professional Data Dude
Dec 5 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Frank Millman | last post by:
Hi all I have a question regarding inheritance. I have come up with a solution, but it is not very elegant - I am sure there is a more pythonic approach. Assume the following class definitions....
1
by: Gerry Sutton | last post by:
Hi All! I have noticed a strange behavior when using a constant identifier to initialize an instance list variable in a base class and then trying to modifying the list in subclasses by using...
4
by: Z.K. | last post by:
I was wondering if someone could tell me how or point me to an appropriate web page that will show me how to subclass a control in vc++.net 2002. What I want to do is to be able to pop up a dialog...
8
by: Lou Pecora | last post by:
I've been scanning Python in a Nutshell, but this seems to be either undoable or so subtle that I don't know how to do it. I want to subclass a base class that is returned from a Standard Library...
1
by: s.lipnevich | last post by:
Hi All, Is anything wrong with the following code? class Superclass(object): def __new__(cls): # Questioning the statement below return super(Superclass, cls).__new__(Subclass) class...
31
by: damacy | last post by:
hi, there. i have a problem writing a program which can obtain ip addresses of machines running in the same local network. say, there are 4 machines present in the network; , , and and if i...
6
by: Me | last post by:
I need to be able to acces non-virtual members of sublcasses via a base class pointer...and without the need for an explicit type cast. I thought a pure virtual getPtr() that acts as a type cast...
4
by: Kurt Smith | last post by:
Hi List: Class inheritance noob here. For context, I have the following base class and subclass: class Base(object): def __init__(self, val): self.val = val
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.