master Pages

Discussion in 'ASP .Net' started by Just Me, Feb 20, 2007.

  1. Just Me

    Just Me Guest

    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
    Just Me, Feb 20, 2007
    #1
    1. Advertising

  2. Just Me

    aWilson Guest

    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
    aWilson, Feb 20, 2007
    #2
    1. Advertising

  3. Just Me

    Just Me Guest

    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" <> wrote in message
    news:...
    > 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

    >
    >
    Just Me, Feb 20, 2007
    #3
  4. Just Me

    bpd Guest

    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" <> wrote in message
    >
    > news:...
    >
    >
    >
    > > 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.
    bpd, Feb 20, 2007
    #4
  5. Just Me

    Just Me Guest

    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" <> wrote in message
    news:...
    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" <> wrote in message
    >
    > news:...
    >
    >
    >
    > > 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, Feb 20, 2007
    #5
  6. Just Me

    Mark Rae Guest

    Mark Rae, Feb 20, 2007
    #6
  7. 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

    >
    >
    >
    =?Utf-8?B?TWlsb3N6IFNrYWxlY2tpIFtNQ0FEXQ==?=, Feb 20, 2007
    #7
  8. Just Me

    Just Me Guest

    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" <> wrote in message
    news:u7%...
    > "Just Me" <news.microsoft.com> wrote in message
    > news:%...
    >
    >> 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
    >
    Just Me, Feb 21, 2007
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Electrified Research
    Replies:
    5
    Views:
    2,457
    =?Utf-8?B?Q293Ym95IChHcmVnb3J5IEEuIEJlYW1lcikgLSBN
    Oct 11, 2005
  2. Doug McCann
    Replies:
    1
    Views:
    1,003
    William Brogden
    Aug 5, 2004
  3. Replies:
    1
    Views:
    3,201
    PeterKellner
    May 16, 2006
  4. Sam
    Replies:
    0
    Views:
    702
  5. Sam
    Replies:
    1
    Views:
    773
Loading...

Share This Page