MasterPage Method Invocation from ContentPage

Discussion in 'ASP .Net' started by User, Dec 1, 2005.

  1. User

    User Guest

    OK, I asked in a reply, but I've wasted far too long so I'm going to put
    a new post out there in hopes that it will be more visible.

    I have a MasterPage. I want to call a method declared in that class from
    a Page that uses the MasterPage. How do I do that?

    public partial class List : System.Web.UI.MasterPage
    {
    protected ArrayList m_SortList;

    public int AddSortChoice( string inString )
    {
    return m_SortList.Add( inString );
    }
    }


    public partial class PostingList : System.Web.UI.Page
    {

    protected void Page_Load(object sender, EventArgs e)
    {
    // this.Master.AddSortChoice("test"); /* <-- doesn't work */
    }
    }

    I've tried:

    - this.Master.AddSortChoice("up");
    - UserControl ctl = (Master)this.Master;
    - A bunch of other zany attempts
    - Googling for call method in masterpage from contentpage

    Any help would be greatly appreciated. Thanks.
     
    User, Dec 1, 2005
    #1
    1. Advertising

  2. I've documented the solution here:
    http://SteveOrr.net/faq/PassDataToMaster.aspx

    --
    I hope this helps,
    Steve C. Orr, MCSD, MVP
    http://SteveOrr.net


    "User" <> wrote in message
    news:...
    > OK, I asked in a reply, but I've wasted far too long so I'm going to put a
    > new post out there in hopes that it will be more visible.
    >
    > I have a MasterPage. I want to call a method declared in that class from a
    > Page that uses the MasterPage. How do I do that?
    >
    > public partial class List : System.Web.UI.MasterPage
    > {
    > protected ArrayList m_SortList;
    >
    > public int AddSortChoice( string inString )
    > {
    > return m_SortList.Add( inString );
    > }
    > }
    >
    >
    > public partial class PostingList : System.Web.UI.Page
    > {
    >
    > protected void Page_Load(object sender, EventArgs e)
    > {
    > // this.Master.AddSortChoice("test"); /* <-- doesn't work */
    > }
    > }
    >
    > I've tried:
    >
    > - this.Master.AddSortChoice("up");
    > - UserControl ctl = (Master)this.Master;
    > - A bunch of other zany attempts
    > - Googling for call method in masterpage from contentpage
    >
    > Any help would be greatly appreciated. Thanks.
     
    Steve C. Orr [MVP, MCSD], Dec 1, 2005
    #2
    1. Advertising

  3. User

    User Guest

    Steve C. Orr [MVP, MCSD] wrote:
    > I've documented the solution here:
    > http://SteveOrr.net/faq/PassDataToMaster.aspx
    >


    Thanks Steve for the reply... but I don't think that's the same. I want
    to call a method on the MasterPage, not pass data to the ContentPage.
    Your solution is going the wrong way.

    In my instance, I have a generic master page for lists. I want to have a
    sorter control on that page. Instead of loading data from the
    ContentPage to the master page (or finding the control), I want to be
    able to call the method AddSortChoice("string") from the ContentPage
    when it loads. That way, all the code for adding the choices to the
    sorter only happens in one place. Am I making sense?


    >> I have a MasterPage. I want to call a method declared in that class
    >> from a Page that uses the MasterPage. How do I do that?
    >>
    >> public partial class List : System.Web.UI.MasterPage
    >> {
    >> protected ArrayList m_SortList;
    >>
    >> public int AddSortChoice( string inString )
    >> {
    >> return m_SortList.Add( inString );
    >> }
    >> }
    >>
    >>
    >> public partial class PostingList : System.Web.UI.Page
    >> {
    >>
    >> protected void Page_Load(object sender, EventArgs e)
    >> {
    >> // this.Master.AddSortChoice("test"); /* <-- doesn't work */
    >> }
    >> }
    >>
    >> I've tried:
    >>
    >> - this.Master.AddSortChoice("up");
    >> - UserControl ctl = (Master)this.Master;
    >> - A bunch of other zany attempts
    >> - Googling for call method in masterpage from contentpage
    >>
    >> Any help would be greatly appreciated. Thanks.
     
    User, Dec 1, 2005
    #3
  4. User

    User Guest

    My bad...

    Here's the solution:

    1. Change the name of my MasterPage
    2. Cast this.Master to the type of my MasterPage (MyList, for example)
    3. Have fun.

    Thanks Steve.


    User wrote:
    > Steve C. Orr [MVP, MCSD] wrote:
    >
    >> I've documented the solution here:
    >> http://SteveOrr.net/faq/PassDataToMaster.aspx
    >>

    >
    > Thanks Steve for the reply... but I don't think that's the same. I want
    > to call a method on the MasterPage, not pass data to the ContentPage.
    > Your solution is going the wrong way.
    >
    > In my instance, I have a generic master page for lists. I want to have a
    > sorter control on that page. Instead of loading data from the
    > ContentPage to the master page (or finding the control), I want to be
    > able to call the method AddSortChoice("string") from the ContentPage
    > when it loads. That way, all the code for adding the choices to the
    > sorter only happens in one place. Am I making sense?
    >
    >
    > >> I have a MasterPage. I want to call a method declared in that class
    > >> from a Page that uses the MasterPage. How do I do that?
    > >>
    > >> public partial class List : System.Web.UI.MasterPage
    > >> {
    > >> protected ArrayList m_SortList;
    > >>
    > >> public int AddSortChoice( string inString )
    > >> {
    > >> return m_SortList.Add( inString );
    > >> }
    > >> }
    > >>
    > >>
    > >> public partial class PostingList : System.Web.UI.Page
    > >> {
    > >>
    > >> protected void Page_Load(object sender, EventArgs e)
    > >> {
    > >> // this.Master.AddSortChoice("test"); /* <-- doesn't work */
    > >> }
    > >> }
    > >>
    > >> I've tried:
    > >>
    > >> - this.Master.AddSortChoice("up");
    > >> - UserControl ctl = (Master)this.Master;
    > >> - A bunch of other zany attempts
    > >> - Googling for call method in masterpage from contentpage
    > >>
    > >> Any help would be greatly appreciated. Thanks.

    >
    >
     
    User, Dec 1, 2005
    #4
  5. you need to cast the Page.Master property to your masterpage class
    and call the method on it.

    for ex:

    ((List)this.Master).AddSortChoice("test");

    HTH,
    <Ram/>


    "User" wrote:

    > OK, I asked in a reply, but I've wasted far too long so I'm going to put
    > a new post out there in hopes that it will be more visible.
    >
    > I have a MasterPage. I want to call a method declared in that class from
    > a Page that uses the MasterPage. How do I do that?
    >
    > public partial class List : System.Web.UI.MasterPage
    > {
    > protected ArrayList m_SortList;
    >
    > public int AddSortChoice( string inString )
    > {
    > return m_SortList.Add( inString );
    > }
    > }
    >
    >
    > public partial class PostingList : System.Web.UI.Page
    > {
    >
    > protected void Page_Load(object sender, EventArgs e)
    > {
    > // this.Master.AddSortChoice("test"); /* <-- doesn't work */
    > }
    > }
    >
    > I've tried:
    >
    > - this.Master.AddSortChoice("up");
    > - UserControl ctl = (Master)this.Master;
    > - A bunch of other zany attempts
    > - Googling for call method in masterpage from contentpage
    >
    > Any help would be greatly appreciated. Thanks.
    >
     
    =?Utf-8?B?UmFt?=, Dec 1, 2005
    #5
  6. On several of your faq's the bottom is cut off:

    http://steveorr.net/freecontrols/misc.aspx

    I'm using Opera.

    :)


    "Steve C. Orr [MVP, MCSD]" <> schreef in bericht
    news:...
    > I've documented the solution here:
    > http://SteveOrr.net/faq/PassDataToMaster.aspx
    >
    > --
    > I hope this helps,
    > Steve C. Orr, MCSD, MVP
    > http://SteveOrr.net
    >
    >
    > "User" <> wrote in message
    > news:...
    >> OK, I asked in a reply, but I've wasted far too long so I'm going to put
    >> a new post out there in hopes that it will be more visible.
    >>
    >> I have a MasterPage. I want to call a method declared in that class from
    >> a Page that uses the MasterPage. How do I do that?
    >>
    >> public partial class List : System.Web.UI.MasterPage
    >> {
    >> protected ArrayList m_SortList;
    >>
    >> public int AddSortChoice( string inString )
    >> {
    >> return m_SortList.Add( inString );
    >> }
    >> }
    >>
    >>
    >> public partial class PostingList : System.Web.UI.Page
    >> {
    >>
    >> protected void Page_Load(object sender, EventArgs e)
    >> {
    >> // this.Master.AddSortChoice("test"); /* <-- doesn't work */
    >> }
    >> }
    >>
    >> I've tried:
    >>
    >> - this.Master.AddSortChoice("up");
    >> - UserControl ctl = (Master)this.Master;
    >> - A bunch of other zany attempts
    >> - Googling for call method in masterpage from contentpage
    >>
    >> Any help would be greatly appreciated. Thanks.

    >
    >
     
    Edwin Knoppert, Dec 1, 2005
    #6
  7. Thanks, I'll investigate.

    "Edwin Knoppert" <> wrote in message
    news:438eb898$0$2335$...
    > On several of your faq's the bottom is cut off:
    >
    > http://steveorr.net/freecontrols/misc.aspx
    >
    > I'm using Opera.
    >
    > :)
     
    Steve C. Orr [MVP, MCSD], Dec 2, 2005
    #7
  8. User

    Scott Allen Guest

    Scott Allen, Dec 2, 2005
    #8
  9. User

    will Guest

    will, Dec 19, 2005
    #9
  10. User

    will Guest

    Hi,
    I've been trying to acheive something similar. I have managed to invoke
    methods within a masterpage from a page however I've had problems
    trying to call such methods from a usercontrol.

    Ideally I'd like to be able to call master page methods from user
    controls with no code required in the page.

    Will.
     
    will, Dec 19, 2005
    #10
    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. Replies:
    1
    Views:
    513
    Scott Allen
    Nov 22, 2005
  2. dawg1998
    Replies:
    2
    Views:
    3,644
    zehramb
    May 31, 2010
  3. =?Utf-8?B?ZGF3ZzE5OTg=?=
    Replies:
    0
    Views:
    500
    =?Utf-8?B?ZGF3ZzE5OTg=?=
    Mar 15, 2006
  4. Replies:
    7
    Views:
    13,277
    TuckWong
    Jan 11, 2013
  5. Elmo Watson
    Replies:
    1
    Views:
    622
    Eliyahu Goldin
    May 8, 2007
Loading...

Share This Page