First Add some controls in Master Page to read from Child Page

  1. <div class="main">
  2. <asp:Label ID="lblMaster" runat="server" Text="Master Label"></asp:Label>
  3. <asp:TextBox ID="txtMaster" runat="server" placeholder="Master Textbox" ></asp:TextBox>
  4. <asp:ContentPlaceHolder ID="MainContent" runat="server" />
  5. </div>

Add Some controls in Child Page

  1. <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="Server">
  2. <br />
  3. <hr />
  4. <asp:Button ID="btnGetMasterPageContent" runat="server" Text="Get Master Page Content" OnClick="btnGetMasterPageContent_Click" />
  5. <asp:Button ID="btnSetMasterPageContent" runat="server" Text="Set Master Page Content" OnClick="btnSetMasterPageContent_Click" />
  6. <br /><br />
  7. <asp:Label ID="lblChild" runat="server" Text="Child Label"></asp:Label>
  8. <asp:TextBox ID="txtChild" placeholder="Child Textbox" runat="server"></asp:TextBox>
  9. </asp:Content>
Now Child Page Code behind
  1. protected void btnGetMasterPageContent_Click(object sender, EventArgs e)
  2. {
  3. Label lblMaster = (Label)Master.FindControl("lblMaster");
  4. TextBox txtMaster = (TextBox)Master.FindControl("txtMaster");
  5. if (lblMaster != null)
  6. {
  7. lblChild.Text = lblMaster.Text;
  8. }
  9. if (txtMaster != null)
  10. {
  11. txtChild.Text = txtMaster.Text;
  12. }
  13. }
  14. protected void btnSetMasterPageContent_Click(object sender, EventArgs e)
  15. {
  16. Label lblMaster = (Label)Master.FindControl("lblMaster");
  17. TextBox txtMaster = (TextBox)Master.FindControl("txtMaster");
  18. if (lblMaster != null)
  19. lblMaster.Text = lblChild.Text;
  20. if (txtMaster != null)
  21. txtMaster.Text = txtChild.Text;
  22. }

Note: Hope now you can Access Master Page Contents as well as can set also data from child page.