PC Review


Reply
Thread Tools Rate Thread

Access property and control of master page from a customized parent page class

 
 
RedHair
Guest
Posts: n/a
 
      22nd Mar 2006
I have a ASP.NET 2.0 web page which inherits a customized base page class
and have a master page,
their relation is as below

Customized base page class --> web page --> master page

How to access the property and control of master page from the customized
base page class?

Btw, I can access the server control of master page from base page class via
Cast + FinndControl,
however this method doesn't work on access a user control. how to solve?

Thanks in advance!


 
Reply With Quote
 
 
 
 
=?Utf-8?B?Y2xpY2tvbg==?=
Guest
Posts: n/a
 
      22nd Mar 2006
You could try exposing the control as a property in the master page.



"RedHair" wrote:

> I have a ASP.NET 2.0 web page which inherits a customized base page class
> and have a master page,
> their relation is as below
>
> Customized base page class --> web page --> master page
>
> How to access the property and control of master page from the customized
> base page class?
>
> Btw, I can access the server control of master page from base page class via
> Cast + FinndControl,
> however this method doesn't work on access a user control. how to solve?
>
> Thanks in advance!
>
>
>

 
Reply With Quote
 
RedHair
Guest
Posts: n/a
 
      22nd Mar 2006
Thanks for reply, however the base class can't access the property of master
page


"clickon" <(E-Mail Removed)> wrote in message
news:2A01DD12-C320-446A-A9CF-(E-Mail Removed)...
> You could try exposing the control as a property in the master page.
>
>
>
> "RedHair" wrote:
>
>> I have a ASP.NET 2.0 web page which inherits a customized base page class
>> and have a master page,
>> their relation is as below
>>
>> Customized base page class --> web page --> master page
>>
>> How to access the property and control of master page from the customized
>> base page class?
>>
>> Btw, I can access the server control of master page from base page class
>> via
>> Cast + FinndControl,
>> however this method doesn't work on access a user control. how to solve?
>>
>> Thanks in advance!
>>
>>
>>



 
Reply With Quote
 
CaffieneRush@gmail.com
Guest
Posts: n/a
 
      22nd Mar 2006
I don't know if I understood your question correctly but here goes.

'Access base class' master page.
Dim myBMP As MasterPage = Me.MyBase.Master

'Find a user control called "myControl" in base class' master
Dim myControl As UserControl = myBMP.FindControl("myControl")
'Or perhaps
Dim myControl As UserControl = CType(MyBMP.FindControl("myControl"),
UserControl)

 
Reply With Quote
 
RedHair
Guest
Posts: n/a
 
      23rd Mar 2006
I am trying to access the page's master page from this page's parent class.


<(E-Mail Removed)>
???????:(E-Mail Removed)...
>I don't know if I understood your question correctly but here goes.
>
> 'Access base class' master page.
> Dim myBMP As MasterPage = Me.MyBase.Master
>
> 'Find a user control called "myControl" in base class' master
> Dim myControl As UserControl = myBMP.FindControl("myControl")
> 'Or perhaps
> Dim myControl As UserControl = CType(MyBMP.FindControl("myControl"),
> UserControl)
>



 
Reply With Quote
 
CaffieneRush@gmail.com
Guest
Posts: n/a
 
      23rd Mar 2006
Accessing the subclass from the base class violates the general OO
principle that the base class should not know the subclass. It makes
the base class dependent on its subclasses.

Having said that, you can pass a reference of the subclass' masterpage
to the base class. I have not tested the following code snippet.
'In base class. Declare a variable to hold a reference to subclass'
masterpage
Protected ChildMaster As MasterPage

'In subclass. Pass the reference to masterpage to base class
Me.MyBase.ChildMaster = Me.Master

Back in the base class you can access subclass' masterpage through
ChildMaster.

However, I would urge you to rethink your design.

Regards.

RedHair wrote:
> I am trying to access the page's master page from this page's parent class.
>
>
> <(E-Mail Removed)>
> ???????:(E-Mail Removed)...
> >I don't know if I understood your question correctly but here goes.
> >
> > 'Access base class' master page.
> > Dim myBMP As MasterPage = Me.MyBase.Master
> >
> > 'Find a user control called "myControl" in base class' master
> > Dim myControl As UserControl = myBMP.FindControl("myControl")
> > 'Or perhaps
> > Dim myControl As UserControl = CType(MyBMP.FindControl("myControl"),
> > UserControl)
> >


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Setting the value of a Master page's control's property using a property of the Master page Nathan Sokalski Microsoft ASP .NET 25 4th Mar 2010 03:42 AM
How can I access a Master Page Public Property from a Base Page =?Utf-8?B?SmF5IFBvbmR5?= Microsoft ASP .NET 6 14th Nov 2007 12:06 PM
Access a Master Page Property from content page CodeBehind Matt Microsoft VB .NET 0 29th Nov 2006 03:41 PM
Page and Parent property of custom server control Charles Zhang Microsoft ASP .NET 1 13th Oct 2006 06:33 AM
Page load of the parent page called twice when a modal dialog is opened from a button click of the user control on the parent page Samy Microsoft ASP .NET 2 15th Aug 2005 04:30 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:44 PM.