Hi,
the Page class has a Master property that you can use.
I created this little sample for you:
The master page:
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="SetLabelsTextFromContentPage.master.cs" Inherits="Master_pages_SetLabelsTextFromContentPage" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:contentplaceholder id="ContentPlaceHolder1" runat="server">
</asp:contentplaceholder>
<asp:Label ID="Label1" runat="server" Text="Label on the Master Page"></asp:Label></div>
</form>
</body>
</html>
The webform:
<%@ Page Language="C#" MasterPageFile="~/Master pages/SetLabelsTextFromContentPage.master" AutoEventWireup="true" CodeFile="SetLabelsTextFromContentPage.aspx.cs" Inherits="Master_pages_SetLabelsTextFromContentPage" Title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Put information on Master Page" />
</asp:Content>
and the codefile for the webform:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class Master_pages_SetLabelsTextFromContentPage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
((Label)Master.FindControl("Label1")).Text = TextBox1.Text;
}
}
The most important thing happens in this line:
((Label)Master.FindControl("Label1")).Text = TextBox1.Text;
With Master.FindControl("Label1") I'm able to find the control. The (Label) casts the control that FindControl gave to a Label control. After that I can set the Text property of the found control equal to the text that I typed into TextBox1 on my webform.
I hope this clarifies things for you.
Grz, Kris.