1.

From the Content page, how can you reference a control on the master page?

Answer»

1. USING the FindControl() method

  • using System;
  • using System.Collections.Generic;
  • using System.Linq;
  • using System.Web;
  • using System.Web.UI;
  • using System.Web.UI.WebControls;
  • public PARTIAL class FindControl : System.Web.UI.Page
{ protected void Page_Load(object sender, EventArgs e) {      //Define Label Control and Fetch the control of MASTER PAGE      Label lbl = (Label)Page.Master.FindControl("lblFirstName");      //Set the value to CONTENT PAGE label control.      lblFindControlUserName.TEXT = "Value Received in Content Page : "+lbl.Text; } }

2. Without using the FindControl() method

Yes, by casting the Master to your MasterPage as shown in the below code SAMPLE:

protected void Page_Load(object sender, EventArgs e)

{     MyMasterPage MP = this.Master;     MP.MyTextBox.Text = "Text Box Found"; }


Discussion

No Comment Found