Search code examples
c#asp.nettextmaster-pagescontentplaceholder

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 = (ContentPlaceHolder)this.Master.FindControl("ContentPlaceHolder1"); 
        ContentPlaceHolder1. ????


 }

Solution

  • 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"));