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

0
nubie 4/21/2007 11:02:24 PM
📁 asp.net.navigation-controls
📃 13714 articles.
⭐ 2 followers.

💬 3 Replies
👁️‍🗨️ 170 Views

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.

 

0
nubie 4/22/2007 6:45:35 AM

Hi,

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

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

form>

In content page, try this code: 

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


Zhao Ji Ma
Sincerely,
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. €
0
Zhao 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.

0
Adam 4/25/2007 12:05:31 PM