473,765 Members | 1,957 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.M asterPage
{
protected ArrayList m_SortList;

public int AddSortChoice( string inString )
{
return m_SortList.Add( inString );
}
}
public partial class PostingList : System.Web.UI.P age
{

protected void Page_Load(objec t sender, EventArgs e)
{
// this.Master.Add SortChoice("tes t"); /* <-- doesn't work */
}
}

I've tried:

- this.Master.Add SortChoice("up" );
- UserControl ctl = (Master)this.Ma ster;
- 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 1914
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.c om> wrote in message
news:e7******** ******@TK2MSFTN GP12.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.M asterPage
{
protected ArrayList m_SortList;

public int AddSortChoice( string inString )
{
return m_SortList.Add( inString );
}
}
public partial class PostingList : System.Web.UI.P age
{

protected void Page_Load(objec t sender, EventArgs e)
{
// this.Master.Add SortChoice("tes t"); /* <-- doesn't work */
}
}

I've tried:

- this.Master.Add SortChoice("up" );
- UserControl ctl = (Master)this.Ma ster;
- 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.M asterPage
{
protected ArrayList m_SortList;

public int AddSortChoice( string inString )
{
return m_SortList.Add( inString );
}
}
public partial class PostingList : System.Web.UI.P age
{

protected void Page_Load(objec t sender, EventArgs e)
{
// this.Master.Add SortChoice("tes t"); /* <-- doesn't work */
}
}

I've tried:

- this.Master.Add SortChoice("up" );
- UserControl ctl = (Master)this.Ma ster;
- 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.M asterPage
>> {
>> protected ArrayList m_SortList;
>>
>> public int AddSortChoice( string inString )
>> {
>> return m_SortList.Add( inString );
>> }
>> }
>>
>>
>> public partial class PostingList : System.Web.UI.P age
>> {
>>
>> protected void Page_Load(objec t sender, EventArgs e)
>> {
>> // this.Master.Add SortChoice("tes t"); /* <-- doesn't work */
>> }
>> }
>>
>> I've tried:
>>
>> - this.Master.Add SortChoice("up" );
>> - UserControl ctl = (Master)this.Ma ster;
>> - 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.Mas ter).AddSortCho ice("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.M asterPage
{
protected ArrayList m_SortList;

public int AddSortChoice( string inString )
{
return m_SortList.Add( inString );
}
}
public partial class PostingList : System.Web.UI.P age
{

protected void Page_Load(objec t sender, EventArgs e)
{
// this.Master.Add SortChoice("tes t"); /* <-- doesn't work */
}
}

I've tried:

- this.Master.Add SortChoice("up" );
- UserControl ctl = (Master)this.Ma ster;
- 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.ne t> schreef in bericht
news:eo******** ******@TK2MSFTN GP14.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.c om> wrote in message
news:e7******** ******@TK2MSFTN GP12.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.M asterPage
{
protected ArrayList m_SortList;

public int AddSortChoice( string inString )
{
return m_SortList.Add( inString );
}
}
public partial class PostingList : System.Web.UI.P age
{

protected void Page_Load(objec t sender, EventArgs e)
{
// this.Master.Add SortChoice("tes t"); /* <-- doesn't work */
}
}

I've tried:

- this.Master.Add SortChoice("up" );
- UserControl ctl = (Master)this.Ma ster;
- 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**@hellobasi c.com> wrote in message
news:43******** **************@ text.nova.plane t.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.ne t> 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.ne t> 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1188
by: phil1bruening | last post by:
Hi, How can I change webcontrols from a contentpage in the masterpage?
9
4350
by: Leffe Andersson | last post by:
Hi folks! I have a MasterPage with some public methods, and I would like to call them from a (app_code) class. Is it possible to set a directive or an assembly reference to a MasterPage from a normal class? I have no problem to call the masterpage's methods from a contentpage, but what I would like to do is someting like this... public partial class MyMaster : System.Web.UI.MasterPage
2
7696
by: dawg1998 | last post by:
I have a page that creates dynamic textboxes based on the number of fields a user chooses to fill out. This process worked great when the page was standalone. However, when I move to a Content/MasterPage setup, the MasterPage Form seems to be interfering with the ability of my code to retrieve the value in the dynamic control. Are there any ideas on why this is happening or how to work-around the problem? What is the syntax to find a...
5
1856
by: jeffmagill | last post by:
Is it possible? I haven't been able to find any information about this. Not on the web, not in books. Is it possible to call a function or subroutine which is defined in a MasterPage from it's derivative ContentPage? Thanks. Jeff
3
1214
by: musosdev | last post by:
Hi guys I'm using a MasterPage for my website rebuild (vs2005, .net2, c#). I want to be able to control the Title element, both on the MasterPage and the Content pages. For example, on each page I want the following to appear for the Title.. SITENAME - some page related title
7
13046
by: Bon | last post by:
Dear all I create a master page with image buttons on the left-hand side for navigation. When a user clicks the student button, the content (i.e. ContentPlaceholder) in masterpage will be changed from default.aspx to students.aspx. I tried to create a subroutine in MasterPage.master.vb to do it. The code is as following. But, the default.aspx's content is shown in MasterPage even I clicked the student button.
1
1845
by: =?Utf-8?B?Sm9obg==?= | last post by:
I have a dropdownlist in masterpage and a big table in contentpage. When ddl selection changes, I want to move a specific row of the table to the top of the contentpage. Can I do something like <a href="#mid"in ddl event handler? Maybe a Javascript? Please advise. Thanks.
4
2202
by: =?Utf-8?B?SmFwZQ==?= | last post by:
Can I refer to the controls on default.aspx from the masterpage? I have a form on the masterpage which sends information that is in a gridview in the default.aspx page.
2
1851
by: Sully | last post by:
I know this is a basic question, but I cannot find the answer. I have a 3 LinkButtons on the masterpage that set a session variable, this session variable does not get relayed to the content page until there are 2 postbacks. MasterPage: protected void lbtn01_Click(object sender, EventArgs e) { Session = "01";
0
9568
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
9955
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9833
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8831
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7378
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5275
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3924
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3531
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.