In the child page, I want to find master page's Content placeholder and add text to it. How do I make that possible?
I tried this much:-
protected void Page_PreInit(object sender, EventArgs e)
{
class1 obj = new class1();
DataTable dt = new DataTable();
dt = obj.get_text();
ContentPlaceHolder ContentPlaceHolder1 = (ContentPlac开发者_JS百科eHolder)this.Master.FindControl("ContentPlaceHolder1");
ContentPlaceHolder1. ????
}
Given you have a valid reference to ContentPlaceHolder1...
In this line:
ContentPlaceHolder1. ????
Do this:
// Add text to the place holder.
ContentPlaceHolder1.Controls.Add(new LiteralControl("my text to insert"));
You cannot add text to a content placeholder. Since it's in a masterpage, you have to add the text to a control on the page you're loading. If you want the text to appear on the master page, you want to add a label or literal outside the content placeholder on the master page and access it the same way you access the content placeholder in your example.
However, given your example, you don't need to do that. You can just set the text on the page you're viewing.
contentPlaceholder1.Controls.Add();
精彩评论