it is very easy to access master page control from content page like
protected void Page_Load(object sender, EventArgs e)
{
// content page load event
DropDownList thisDropDown = this.Master.FindControl("someDropDown") as DropDownList;
userLabel.Text = thisDropDown.SelectedValue;
}
but how could i access controls of content page from master page. suppose a textbox there in content page and one button is there in master page. i want that when i will click on master page button then i want to show the text of textbox in the content page in the label of master page. how to achieve it. please help me with code sample. thanks.
In master page button click event should access page contents by:-
protected void Button1_Click(object sender, EventArgs e)
{
TextBox TextBox1 = (TextBox)ContentPlaceHolder1.FindControl("TextBox1");
if (TextBox1 != null)
{
Label1.Text = TextBox1.Text;
}
}
It's been a while, but I believe you can do so by using the ContentPlaceHolder as a reference:
Control control = this.myContentPlaceHolder.FindControl("ContentPageControlID");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With