Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Access property and control of master page from a customized parent page class

Reply
Thread Tools

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

 
 
RedHair
Guest
Posts: n/a
 
      03-22-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
 
      03-22-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
 
      03-22-2006
Thanks for reply, however the base class can't access the property of master
page


"clickon" <(E-Mail Removed)> wrote in message
news:(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
 
      03-22-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
 
      03-23-2006
I am trying to access the page's master page from this page's parent class.


<(E-Mail Removed)>
???????:(E-Mail Removed) groups.com...
>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
 
      03-23-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) groups.com...
> >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

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
How to Access Master Page Controls from page.aspx doesn't inherit from master SerpentKiss2010 ASP .Net 0 04-06-2011 02:46 PM
Setting the value of a Master page's control's property using a property of the Master page Nathan Sokalski ASP .Net 25 03-04-2010 03:42 AM
If a class Child inherits from Parent, how to implementChild.some_method if Parent.some_method() returns Parent instance ? metal Python 8 10-30-2009 10:31 AM
Access property and control of master page from a customized parent page class RedHair ASP .Net Web Controls 5 03-23-2006 01:39 PM
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 ASP .Net 2 08-15-2005 03:30 PM



Advertisments