Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > master Pages

Reply
Thread Tools

master Pages

 
 
Just Me
Guest
Posts: n/a
 
      02-20-2007
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



 
Reply With Quote
 
 
 
 
aWilson
Guest
Posts: n/a
 
      02-20-2007
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";
}


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



 
Reply With Quote
 
 
 
 
Just Me
Guest
Posts: n/a
 
      02-20-2007
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.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>")).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";
> }
>
>
> 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

>
>



 
Reply With Quote
 
bpd
Guest
Posts: n/a
 
      02-20-2007
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" <(E-Mail Removed)> wrote in message
>
> news:(E-Mail Removed) oups.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.

 
Reply With Quote
 
Just Me
Guest
Posts: n/a
 
      02-20-2007
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.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" <(E-Mail Removed)> wrote in message
>
> news:(E-Mail Removed) oups.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.


 
Reply With Quote
 
Mark Rae
Guest
Posts: n/a
 
      02-20-2007
"Just Me" <news.microsoft.com> wrote in message
news:%(E-Mail Removed)...

> 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


 
Reply With Quote
 
=?Utf-8?B?TWlsb3N6IFNrYWxlY2tpIFtNQ0FEXQ==?=
Guest
Posts: n/a
 
      02-20-2007
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" wrote:

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

>
>
>

 
Reply With Quote
 
Just Me
Guest
Posts: n/a
 
      02-21-2007
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" <(E-Mail Removed)> wrote in message
news:u7%(E-Mail Removed)...
> "Just Me" <news.microsoft.com> wrote in message
> news:%(E-Mail Removed)...
>
>> 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
>



 
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
2nd Post: VB Master-Details Edit (Separate Pages), Response Redirect to Master Page Databinding Issue... Sam ASP .Net 1 07-20-2006 06:17 PM
VB Master-Details Edit (Separate Pages), Response Redirect to Master Page Databinding Issue... Sam ASP .Net 0 07-20-2006 02:31 AM
Cross Page Post Back When Using Mixture of Master Pages and Non-Master Pages Jason@webbit.com ASP .Net 1 05-16-2006 02:00 PM
Master Pages Great! But what about Master User Controls? Electrified Research ASP .Net 5 10-11-2005 02:32 PM
seeking servlet "Master" keep getting "Master/servlet/Master" not found. Tomcat 5.0.25 Doug McCann Java 1 08-05-2004 09:16 PM



Advertisments