473,325 Members | 2,712 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,325 software developers and data experts.

Access pages base class properties from User Control

Hi,

I have some properties that are common to all pages so I have created a base
class which every page inherits from. I now also want to use these
properties within User Controls on the page. Is there any way to get to
these properties through the parent property of the user control - I can't
seem to figure out how to get there. If I can't do this, do I have to do the
same thing as the page and create a base user control class with the same
code in - Seems silly to have to execute the same code twice on a page?

Thanks in advance for any help

Mike
Nov 18 '05 #1
3 2260
UserControl.Page return reference to Page object contains this control.
Since you use another class for your page you must cast this property to
your page class:
For example
if your base page class named MyBasePage

((MyBasePage)MyUserControl.Page).[my base page property/method]

HTH

"Mikip" <mi***@plugthenet.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Hi,

I have some properties that are common to all pages so I have created a base class which every page inherits from. I now also want to use these
properties within User Controls on the page. Is there any way to get to
these properties through the parent property of the user control - I can't
seem to figure out how to get there. If I can't do this, do I have to do the same thing as the page and create a base user control class with the same
code in - Seems silly to have to execute the same code twice on a page?

Thanks in advance for any help

Mike

Nov 18 '05 #2
Anatoly,
Thanks for the reply...yes, if i maybe would have used a few more of my
limited neurons, I would have seen this! Incidently, do you think its better
to declare a private field in the UserControl class, do the cast once
assigning the base property to this field and use the private field within
the UserControl class. Will it save some performance not having to make the
cast everytime I want to use a base class property.?

Thx

Mike
"Anatoly" <an*****@hotmail.com> wrote in message
news:uO**************@tk2msftngp13.phx.gbl...
UserControl.Page return reference to Page object contains this control.
Since you use another class for your page you must cast this property to
your page class:
For example
if your base page class named MyBasePage

((MyBasePage)MyUserControl.Page).[my base page property/method]

HTH

"Mikip" <mi***@plugthenet.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Hi,

I have some properties that are common to all pages so I have created a

base
class which every page inherits from. I now also want to use these
properties within User Controls on the page. Is there any way to get to
these properties through the parent property of the user control - I can't seem to figure out how to get there. If I can't do this, do I have to do

the
same thing as the page and create a base user control class with the same code in - Seems silly to have to execute the same code twice on a page?

Thanks in advance for any help

Mike


Nov 18 '05 #3
Mike

In reality, this smells of bad design since your UserControl now is aware of
your Base Page Class and "talks" to it. Of course, if your UserControl and
base page are specific to this application then its not too bad.

Typically UserControls (like other controls) should be agnostic of the
specific page.

--
Shiv R. Kumar
http://www.matlus.com
Nov 18 '05 #4

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

Similar topics

6
by: Peter Frost | last post by:
Please help I don't know if this is possible but what I would really like to do is to use On Error Goto to capture the code that is being executed when an error occurs. Any help would be much...
7
by: Baski | last post by:
Base class: class AssetBase { string _clli; public string CLLI { get
2
by: paul meaney | last post by:
All, myself and another developer have been staring blankly at a screen for the past 48 hours and are wondering just what stunningly obvious thing we are missing. We are trying to load up 2...
3
by: Brent Minder | last post by:
What is the most efficient way to code asp.net pages when you break your page up into user controls? For example: If you have a page with a header (control .ascx), body, and footer (control...
14
by: multiformity | last post by:
So I have been working on an opensource project for a while, and decided to really try to make it look better after focusing on the functionality most of this time. Up to now, I have simply used a...
3
by: Jeff User | last post by:
Hello I am using C#, .net1.1 Vis Studio 2003 I am using homeBase.aspx.cs page as a base for several other aspx/aspx.cs web pages. The base page handles some operations that are common to all...
4
by: RedHair | last post by:
I have a base page class A which inherits System.Web.UI.Page class then a aspx page B inherits class A and have a master page C. There is a property D (a string variable) in the master page C. ...
4
by: Boris Yeltsin | last post by:
OK, on my Master Page I have a control: <a id="hypTabAccount" href="#" runat="server">Account</a> Now, in the code-behind (Root.master.vb) I can refer to it simply thus: ...
6
by: =?Utf-8?B?SmF5IFBvbmR5?= | last post by:
I am trying to access a Public property on a Master Page from a Base Page. On the content pages I have the MasterType Directive set up as follows: <%@ MasterType virtualpath="~/Master.master" %>...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
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...

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.