469,903 Members | 2,238 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,903 developers. It's quick & easy.

MasterPage Method Invocation from ContentPage

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.
Dec 1 '05 #1
9 1685
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" <us**@example.com> wrote in message
news:e7**************@TK2MSFTNGP12.phx.gbl...
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.

Dec 1 '05 #2
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.

Dec 1 '05 #3
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.


Dec 1 '05 #4
Ram
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.

Dec 1 '05 #5
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]" <St***@Orr.net> schreef in bericht
news:eo**************@TK2MSFTNGP14.phx.gbl...
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" <us**@example.com> wrote in message
news:e7**************@TK2MSFTNGP12.phx.gbl...
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.


Dec 1 '05 #6
Thanks, I'll investigate.

"Edwin Knoppert" <ne**@hellobasic.com> wrote in message
news:43**********************@text.nova.planet.nl. ..
On several of your faq's the bottom is cut off:

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

I'm using Opera.

:)

Dec 2 '05 #7
On Wed, 30 Nov 2005 17:12:18 -0800, "Steve C. Orr [MVP, MCSD]"
<St***@Orr.net> wrote:
I've documented the solution here:
http://SteveOrr.net/faq/PassDataToMaster.aspx


Have you tried @ MasterType ?
http://odetocode.com/Blogs/scott/arc...7/16/1944.aspx

--
Scott
http://www.OdeToCode.com/blogs/scott/
Dec 2 '05 #8

Scott Allen wrote:
On Wed, 30 Nov 2005 17:12:18 -0800, "Steve C. Orr [MVP, MCSD]"
<St***@Orr.net> wrote:
I've documented the solution here:
http://SteveOrr.net/faq/PassDataToMaster.aspx


Have you tried @ MasterType ?
http://odetocode.com/Blogs/scott/arc...7/16/1944.aspx

--
Scott
http://www.OdeToCode.com/blogs/scott/


Dec 19 '05 #9
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.

Dec 19 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by phil1bruening | last post: by
9 posts views Thread by Leffe Andersson | last post: by
5 posts views Thread by jeffmagill | last post: by
1 post views Thread by =?Utf-8?B?Sm9obg==?= | last post: by
4 posts views Thread by =?Utf-8?B?SmFwZQ==?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.