Overiding Page Class

J

John Saunders

Vincent V said:
Hey im Overiding OnInit in my Custom Page class
What i want to be able to do is pass in Some Values
Ie PageID PageCategory, PageSubCategory
How can i pass in some Vairables So my Custom Page class can see these

I'm not sure what you mean here. If you want to set some values inside of
your custom page class, you can add public properties to the custom page
class. You can then create a separate control which has mirror copies of
those properties, and which simply sets them in the custom page class:

<wc:MyControl PageID="p1" PageCategory="Company"
PageSubCategory="Investment" />

MyControl would save the property values in class members until OnLoad is
called, then:

protected override void OnLoad(EventArgs e)
{
MyPage p = this.Page as MyPage;
if (p == null)
return;

p.PageID = m_PageID;
p.PageCategory = m_PageCategory;
p.PageSubCategory = m_PageSubCategory;

base.OnLoad(e);
}

....
The problem seems that Im using Overload that cuases only One of the OnInits
To Fire

When you override a method, you should almost always call the base class
method. When you call it depends on the nature of the method, but in this
case, call base.OnInit(e) at the end of your OnInit override.
 
V

Vincent V

Hey im Overiding OnInit in my Custom Page class
What i want to be able to do is pass in Some Values
Ie PageID PageCategory, PageSubCategory
How can i pass in some Vairables So my Custom Page class can see these


Imports System.Web

Imports System.Web.UI

Imports System.Data

Namespace MTT.PageClasses

Public Class GenericPage

Inherits System.Web.UI.Page

Protected Overrides Sub OnInit(ByVal e As System.EventArgs)

Dim myCtrl As Control

For Each myCtrl In Page.Controls

Response.Write(myCtrl.ID)

Next



End Sub

End Class

End Namespace


Also another question is it possible to Inherit The page class more than
once
I want a GenericPageClass That Does Some Work on OnInit

I want Another MainPageClass That Inherits Generic Page Class And i want to
do some work OnInit Int this sub
The problem seems that Im using Overload that cuases only One of the OnInits
To Fire

Is there a way i can get these 2 OnInit Subs Perform Different to the one
page

Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top