Content page accessing master page controls?

I'm probably that much of a noob that I've deviated from the path authors of ASP.NET 2.0 thought of how master and content pages should off been used...

Looking from the outside it seemed logical to me that (even on this website) a search text box should be part of a master page and a page that displays results should be a content page...

So the problem I'm having (if my hunch about that search textbox control in the header of say even this very website being part of a master page, and result page that subsequently loads underneath the header after you click go being a content page) is how do (by which means) I send data from the search textbox (a control in the master page) to the content page?!

 This must be a real easy thing to do, it's just that I'm a noob new to ASP.NET...

I have tried using a solution I found on 4GuysFromRolla website, but I couldn't get it to work for me!? Please is there any example code out there to what I sould do to pass data entered into search text box to the search page?! I'm preety sure in ASP.NET 2.0 you should use stuffing the Request object with parameters (even though I'm not sure how to do that even too, since I'm using controls here instead of making my page out of Response.Write statements...) like say in plain vanilla JSP, or should you!?

 TIA, a n00b

4/21/2007 11:02:24 PM 13714 articles. 0 followers. Follow

3 Replies

Similar Articles

[PageSpeed] 42
Get it on Google Play
Get it on Apple App Store

Ok. I've read what I've wrote and it might be a bit incoherent... mostly 'cause I don't know much about what I'm asking :P sorry about that.

So I've searched a bit more around and have found Request.Params("param_name") way of transfering data between pages. So my new questions is please is that a credible solution for what I want to do, that is to make a search textbox in a master page, and a button beside it, that would have a PostBackUrl that leads to my search content page and in its OnClick event handling procedure would stuff the .Text content (property) of search textbox, so I could in, say, a Page_Init event of the search content page read that value, probably again by accessing the same Request object? Or should I maybe try to use a Session object to transfer data from a master page to its content pages?

I guess I'm asking is what is the best practice for data transfer from a master page to its content pages??? Some example code too would be really great. Thanks in advance, again.


4/22/2007 6:45:35 AM


There is a property of the Page class called Page.Master property. You can try this to access MasterPage properties in content page for interaction.

For example, if there is a header label in Master Page:

<form id="form1" runat="server">

 <asp:Label runat="server" ID="HeaderLabel"
Text="Header1" />

    <asp:contentplaceholder id="ContentPlaceHolder1" runat="server">


In content page, try this code: 

Label lblHeader = (Label)(Master.FindControl("HeaderLabel"));
lblHeader.Text = "New Head";

Zhao Ji Ma
Microsoft Online Community Support

“Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread. ”
4/25/2007 8:47:33 AM

You could achieve your desired functionality through delegates and events. Take a look at the following tutorial: Creating a Common Toolbar in ASP.NET 2.0 using MasterPage, Delegate and Events.

4/25/2007 12:05:31 PM

Similar Artilces:

Content controls have to be top-level controls in a content page or a nested master page that references a master page.
Why in the world am I getting this error? The solutions I have seen either don't apply or don't work.  Here is my master page code:<%@ Master Language="C#" AutoEventWireup="false" CodeFile="TechLMSMasters/MainSide.master.cs" Inherits="MainSide" %> <%@ Register TagPrefix="usercontrol" TagName="Search" Src="~/library/uc/Search.ascx" %> <%@ Register TagPrefix="usercontrol" TagName="UserName" Src="~/library/uc/UserNameDisplay.ascx" %><!DOCTYPE html PUBLI...

Error : Content controls have to be top-level controls in a content page or a nested master page that references a master page.
when I make a directory on my root, and in that directory I put a masterpage and a web form ... I get always an error : Content controls have to be top-level controls in a content page or a nested master page that references a master page.   Does somebody know what the problem is ? Is it possible you can't set a masterpage in a directory ... ?Kind Regards,Joeri Pansaerts.From Bruges, Belgium :) i've founded ... I had to nest my masterpage ...Kind Regards,Joeri Pansaerts.From Bruges, Belgium :) Hi Joeri Pansaerts, I am receiving the same error as the one posted her...

ERROR Content controls have to be top-level controls in a content page or a nested master page that references a master page.
This all used to work until about 5 minutes ago. Did I change something? For some reason I am now getting this error: Content controls have to be top-level controls in a content page or a nested master page that references a master page. What I have:  I have a masterpage inside of a directory. That directory is a first level directory with its own web.config file....The whole thing is protected by the web.config file above it (in the main public directory). That main public directory has a masterpage as well. I am not currently linking the two masterpages together becuase...

Need to access a Label Control on the Master Page from a user control attached to a content page
Hello all, I have a master page (say  site.master)  with a status Label in it. I have a content page ( say content.aspx)  that has a user control (say usercontrol.ascx). One of the Button Click Events in the usercontrol.ascx needs to pass on some text onto the status label on the masterpage(LabelStatusMsg) and display it. I have been able to do this directly off a content page (content.aspx) by using the following code (VB)  on the master page <%@ MasterType virtualpath="~/site.master" %> and Dim mpLabel As Label = CType(Master.FindControl("LabelStatusMsg"),...

Accessing Controls Content Pages from Master Page
how do i access controls content pages from master page?Its all about coding! I would raise an event from the master page and handle it on the content page.  You can commuicate any data through customized event args.  This article explains in detail how to raise and consume an event:  HTH,Phillip Williams, Let's say your master page has a textbox whose ID is MasterTextBox. TextBox tb = Page.Master.FindControl("MasterTextBox") as TextBox;...

Access Content Page Control from Master Page
I use Master page in my application. i want to access the content page control (Text Box)  from master page and change the control (Text Box) value. i cant find the text box by using Findcontrol also Let’s turn to the FindControl documentation on MSDN. FindControl searches the current naming container for the specified server control. Master.FindControl("ContentPageHolder1").FindControl(TextBox) Reading this nice article.   MPI never desire to converse with a man who has written more than he hasread. -Samuel Johnson, lexic...

Accessing master page controls from content page
Hello,Here's a snippet from my listing.master page:<%@ master Language="C#" %>     public string Listing_Name    {        get { return lis_name.Text; }    }    protected void Page_Load(object sender, EventArgs e)    {       lis_name.Text = "Hello World"    } ---------------------------------------------------------------------------------------------------------------In my content page, Master.Listing_Name shows blank, why?<...

Accessing Content Page Control From Master Page
I'd like to access the value of a control residing on a content page from the associated master page. Can anyone point me in the right direction?   Thanks When you know the classname of your page, use: (in VB.NET) CType(Page, classname).ControlID.propertyName But this code will go wrong on all the other pages, so you have to check on which page you are. This being said, I advise you to consider another approach.Your master page should not use code that depends on the design of a particular content page. Your content pages should depend on your master page, not the other ...

Problem Accessing Page Controls in a page that has a master page.
Hi,  I have a problem with accessing the controls of a page that has a masterpage. I am trying to access the Page.Controls from the code behind in the class file but no controls are returned.I can access single controls (ex. txtAddress.Text) but not the whole array of controls (ex. Page.Controls).  The controls structure is..                                 MasterPage  >  PlaceHolder > MyPage.aspx &n...

accessing repeater control in master page from content page
Hello,In my master page, I have a repeater control named "repJobs" and I made it public like so:    public Repeater Rep_Jobs    {        set         {             repJobs.DataSource = value;            repJobs.DataBind();        }    }    From my content page, I tried to assign a datasource to it (a DataTable named "dt") ...

How to access a control in the Content Page from javascript in Master Page?
How do I access a control in the Content Page from javascript in Master Page? Say, I have a dropdown list 'CountryDDL' in my Content Page. When I click on a button in the Content Page, I call a javascript function. The javascript file is included in the master page. From within this javascript function, I have to access CountryDDL and find the selected index etc... Because of Master page - content page hierarchy, document.getElementById('CountryDDL') doesnt seem to work. Is there  any alternate approach? use  document.getElementById('<%Countr...

Problem to use TreeView Control in a 'content page' This Error Occur "Only Content controls are allowed directly in a content page that contains Content controls."
hi I am trying to use the TreeView Control inside the content page (Page that has a master page is a content page). On compiling the project I got the following ASP.Net runtime error: "Only Content controls are allowed directly in a content page that contains Content controls."B@b@R J Issue resolved. I was putting script tag in the content page that is not allowed. when remove the script from content page problem is resolved.B@b@R J...

How to access Master page file contents in user control page?
Hi Friends,My problem scenario:I have a masterpage. In that I have 5 <a ...>Show Text</a> parts ok.I have created a default.aspx. I referenced the masterpage in it.I have now products.ascx user control file.This will be shown in Default's contentpage holder right.Now i want to access masterpage file's anchors along with its text in products.ascx . How can i achieve it? or is there any workaorund for it? pl fell free if my problem dowsn't elaborate itself.ThanksPrashant V. Your user control shouldn't access the Master page directly, as it will lead to a direct d...

Access Master Page control in Content Page and Process Events
<p> Hi All, At My Master Page , I have TreeView control and I am binding this treeview from one of my content page. Which is fine. Now At the same content page I want to detect the click event on the treenode and accessing selectedNode. How do I do that Which Event I need to use at my content page. Please suggest me. Basically I want to retrieve my TreeNode ID. As in case of TreeView I know the id (TreeView name) so I can find my treecontrol but here selected TreeNode can be anything and depend on Selected TreeNode value I will be showing data in my user interface. thanks in ad...

Web resources about - Content page accessing master page controls? -

Highest Percentage Of Opera Mini Users Accessing Facebook? Macau
If you were asked to guess which country had the highest percentage of users of Opera mobile Web browser Opera Mini users accessing Facebook ...

International Users Accessing Facebook Places Through US VPN Accounts
By using a virtual private network (VPN) hosted in the United States, Facebook users from around the world are accessing Facebook Places. The ...

What are some alternatives to Yodlee for accessing bank information?
Clay Loveless , Founder, Jexy. Co-founder, Mashery. Founder, Jexy. Co-founder, Mashery.

Cloud Console - Accessing files in cloud storage for iPad on the iTunes App Store
Get Cloud Console - Accessing files in cloud storage on the App Store. See screenshots and ratings, and read customer reviews.

Meryl Streep On Accessing The Characters Within - YouTube
Meryl Streep talks about the importance of an actors work representing their ability. CONNECT WITH AFI: ...

Accessing the Future Fund a sensible proposal, says super expert Daryl Dixon
As portfolios go, the Future Fund's asset allocation is concentrated in higher-risk investment, including equities and alternative assets.

Accessing my Super
I'm 57 - can I access my super?

Australia, US accessing Indonesian telephone data, leaked documents show
Newly disclosed documents from former US intelligence contractor Edward Snowden have revealed that Australian intelligence efforts against Indonesia ...

Euthanasia advocate Philip Nitschke detained at Melbourne Airport, accuses Customs officials of accessing ...
Euthanasia advocate Philip Nitschke has accused Customs officials of accessing hundreds of patients' sensitive records on his laptop after detaining ...

Frances Abbott scholarship: Sydney woman pleads guilty to accessing Whitehouse Institute records on PM's ...
A Sydney woman who leaked the student records of Tony Abbott's daughter pleads guilty. A Sydney woman who leaked the student records of Prime ...

Resources last updated: 1/21/2016 12:02:56 PM