MasterPage Method Invocation from ContentPage


U

User

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

Advertisements

U

User

Steve said:

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?

 
U

User

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

Guest

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/>
 
Ad

Advertisements

Ad

Advertisements

W

will

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.
 

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

Top