Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > MasterPage Method Invocation from ContentPage

Reply
Thread Tools

MasterPage Method Invocation from ContentPage

 
 
User
Guest
Posts: n/a
 
      12-01-2005
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.
 
Reply With Quote
 
 
 
 
Steve C. Orr [MVP, MCSD]
Guest
Posts: n/a
 
      12-01-2005
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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.



 
Reply With Quote
 
 
 
 
User
Guest
Posts: n/a
 
      12-01-2005
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.



 
Reply With Quote
 
User
Guest
Posts: n/a
 
      12-01-2005
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.

>
>

 
Reply With Quote
 
=?Utf-8?B?UmFt?=
Guest
Posts: n/a
 
      12-01-2005
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.
>

 
Reply With Quote
 
Edwin Knoppert
Guest
Posts: n/a
 
      12-01-2005
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]" <(E-Mail Removed)> schreef in bericht
news:(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> 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.

>
>



 
Reply With Quote
 
Steve C. Orr [MVP, MCSD]
Guest
Posts: n/a
 
      12-02-2005
Thanks, I'll investigate.

"Edwin Knoppert" <(E-Mail Removed)> wrote in message
news:438eb898$0$2335$(E-Mail Removed). ..
> On several of your faq's the bottom is cut off:
>
> http://steveorr.net/freecontrols/misc.aspx
>
> I'm using Opera.
>
>



 
Reply With Quote
 
Scott Allen
Guest
Posts: n/a
 
      12-02-2005
On Wed, 30 Nov 2005 17:12:18 -0800, "Steve C. Orr [MVP, MCSD]"
<(E-Mail Removed)> 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/
 
Reply With Quote
 
will
Guest
Posts: n/a
 
      12-19-2005

Scott Allen wrote:
> On Wed, 30 Nov 2005 17:12:18 -0800, "Steve C. Orr [MVP, MCSD]"
> <(E-Mail Removed)> 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/


 
Reply With Quote
 
will
Guest
Posts: n/a
 
      12-19-2005
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.

 
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
Calling MasterPage Subroutines from a ContentPage jeffmagill@gmail.com ASP .Net 7 01-11-2013 03:54 AM
Finding Value of Dynamic Control in MasterPage/ContentPage System dawg1998 ASP .Net 2 05-31-2010 06:19 AM
GetElementbyID question - within MasterPage/contentpage - within tables Elmo Watson ASP .Net 1 05-08-2007 05:12 PM
Finding Value of Dynamic Control in MasterPage/ContentPage System =?Utf-8?B?ZGF3ZzE5OTg=?= ASP .Net 0 03-15-2006 05:26 PM
Change Webcontrols from a Contentpage in the Masterpage phil1bruening@web.de ASP .Net 1 11-22-2005 03:39 PM



Advertisments