Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

master Pages

3 views
Skip to first unread message

Just Me

unread,
Feb 20, 2007, 1:14:42 PM2/20/07
to
Hi

I have a master page with a control on it, but I need to set a property of
that control from the content.

my master page is called Admin.Master and the class is Admin.


I have tried this

dim mp as Admin

mp = Ctype(me.master, Admin)


But I get the error that ASP.Master_Admin cannot be converted to Admin

How can I do this ?

Thanks

aWilson

unread,
Feb 20, 2007, 1:25:43 PM2/20/07
to
You should be able to access the master page control via Page.Master.
The below is an example in c#.

((ControlType)Page.Master.Controls[0].FindControl("<the_control>")).PropertyToSet
= "" ;

If you go route its better to write it as..

ControlType myControl =
(ControlType)Page.Master.Controls[0].FindControl("<control_id>");

if (myControl != null) {
myControl.Property = "blah";

Just Me

unread,
Feb 20, 2007, 1:32:48 PM2/20/07
to
Hi

I see your point, but It should be possible to do this I have written a
function in the master page which sets the user control property.

Now all I need to do is to be able to call the function on the master page.
In design time, the page.master property does not return the 'Type' of the
master page as they of course are potentially different.

In which case I need to cast the returned type so I can make a call to this
function.

"aWilson" <a.wil...@gmail.com> wrote in message
news:1171995943.8...@k78g2000cwa.googlegroups.com...

bpd

unread,
Feb 20, 2007, 2:17:02 PM2/20/07
to
On Feb 20, 1:32 pm, "Just Me" <news.microsoft.com> wrote:
> Hi
>
> I see your point, but It should be possible to do this I have written a
> function in the master page which sets the user control property.
>
> Now all I need to do is to be able to call the function on the master page.
> In design time, the page.master property does not return the 'Type' of the
> master page as they of course are potentially different.
>
> In which case I need to cast the returned type so I can make a call to this
> function.
>
> "aWilson" <a.wilso...@gmail.com> wrote in message

>
> news:1171995943.8...@k78g2000cwa.googlegroups.com...
>
>
>
> > You should be able to access the master page control via Page.Master.
> > The below is an example in c#.
>
> > ((ControlType)Page.Master.Controls[0].FindControl("<the_control>")).Propert­yToSet

> > = "" ;
>
> > If you go route its better to write it as..
>
> > ControlType myControl =
> > (ControlType)Page.Master.Controls[0].FindControl("<control_id>");
>
> > if (myControl != null) {
> > myControl.Property = "blah";
> > }
>
> > On Feb 20, 11:14 am, "Just Me" <news.microsoft.com> wrote:
> >> Hi
>
> >> I have a master page with a control on it, but I need to set a property
> >> of
> >> that control from the content.
>
> >> my master page is called Admin.Master and the class is Admin.
>
> >> I have tried this
>
> >> dim mp as Admin
>
> >> mp = Ctype(me.master, Admin)
>
> >> But I get the error that ASP.Master_Admin cannot be converted to Admin
>
> >> How can I do this ?
>
> >> Thanks- Hide quoted text -
>
> - Show quoted text -

I'm a little confused at what you're needing, but you should be able
to reference a property
on the master page by doing the following:
((<your master page name>)Master).<master page property name> =
<some value>
or
<some local variable> = ((<your master page name>)Master).<master
page property name>

Also to keep in mind is the sequence in which the events fire.

Just Me

unread,
Feb 20, 2007, 2:28:23 PM2/20/07
to
I have this function in my master page.


Public Sub UserDisplayMessage(ByVal message As String, ByVal UserMessageType
As ScreenMessageType)

Me.AdminHeader1.UserDisplayMessage(message, UserMessageType)

End Sub

From the webcontent page, Ineed to reference it, but it does not appear Me.
. . . .

"bpd" <bryan...@rollcoater.com> wrote in message
news:1171999022.7...@v33g2000cwv.googlegroups.com...


On Feb 20, 1:32 pm, "Just Me" <news.microsoft.com> wrote:
> Hi
>
> I see your point, but It should be possible to do this I have written a
> function in the master page which sets the user control property.
>
> Now all I need to do is to be able to call the function on the master
> page.
> In design time, the page.master property does not return the 'Type' of the
> master page as they of course are potentially different.
>
> In which case I need to cast the returned type so I can make a call to
> this
> function.
>
> "aWilson" <a.wilso...@gmail.com> wrote in message
>
> news:1171995943.8...@k78g2000cwa.googlegroups.com...
>
>
>
> > You should be able to access the master page control via Page.Master.
> > The below is an example in c#.
>

> > ((ControlType)Page.Master.Controls[0].FindControl("<the_control>")).Propert軌ToSet

Mark Rae

unread,
Feb 20, 2007, 4:01:37 PM2/20/07
to
"Just Me" <news.microsoft.com> wrote in message
news:%239X2cVS...@TK2MSFTNGP05.phx.gbl...

> From the webcontent page, Ineed to reference it, but it does not appear
> Me.

Have you forgotten to add the MasterType directive...?
http://www.codeproject.com/aspnet/InsideMasterPages.asp


Milosz Skalecki [MCAD]

unread,
Feb 20, 2007, 4:37:10 PM2/20/07
to
Wilson,

Sorry to say that but you should not do that. If internal implementation
details change in future you will instroduce a bug (i.e, they wrap it with
another container)It's better to expose a property from master page and cast
Master property of the content page to actuall master page type (or use
@MasterType page directive). In addition findcontrol approach is not
supported by compiler, and in case you change / remove / delete the controls
it's more likely you forget about the FindControl() code and will introduce a
bug. Whilst second approach in this case would generate a compiler error.

Regards
--
Milosz

Just Me

unread,
Feb 21, 2007, 1:46:30 PM2/21/07
to
I was not aware of that, I see it shadows the Master poperty which is cool.
Its still messy really, because I still have to add a function to every page
to access this Master. I have a user control which i want to set the
property of on the master, so I have

1.) A function in the masters user control.
2.) A function in the master to set the user control
3.) A manully inserted function to call the master function in each page
derived from it.

Kinda makes things overly complicated.

I wonder if master pages are actually worth it, when you can acheive similar
results from using user controls without all the agravation. This also
includes of course the fact all controls on the loose there primitive ID so
style sheets become a pain,


"Mark Rae" <ma...@markNOSPAMrae.com> wrote in message
news:u7%233QJTV...@TK2MSFTNGP03.phx.gbl...

0 new messages