Code for accessing master control to content page in Asp.net.


Hi

Using this code we can access the master control to content page

protected void Button1_Click(object sender, EventArgs e)
{
Label lblName = FindControlRecursive(this.Master, “label1”) as Label;
TextBox1.Text = lblName.Text;
}
public static Control FindControlRecursive(Control Root, string Id)
{

if (Root.ID == Id)

return Root;

foreach (Control Ctl in Root.Controls)
{

Control FoundCtl = FindControlRecursive(Ctl, Id);

if (FoundCtl != null)

return FoundCtl;

}

return null;

}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: