master Pages

J

Just Me

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
 
A

aWilson

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";
}
 
J

Just Me

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 said:
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";
}


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
 
B

bpd

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.




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";
}

- 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.
 
J

Just Me

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.
.. . . .





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.




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";
}

- 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.
 
G

Guest

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


aWilson said:
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";
}


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
 
J

Just Me

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,
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top