Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET
Help Pls
 
You are creating an ASP.NET Web site. The site has a master page named Custom.master. The code-behind
file for Custom.master contains the following code segment. public partial class CustomMaster : MasterPage {
public string Region
{
get; set;
}
protected void Page_Load(object sender, EventArgs e)
{}}
You create a new ASP.NET page and specify Custom.master as its master page.
You add a Label control named lblRegion to the new page.
You need to display the value of the master page's Region property in lblRegion.
What should you do?
A. Add the following code segment to the Page_Load method of the page code-behind file.
CustomMaster custom = this.Parent as CustomMaster;
lblRegion.Text = custom.Region;
B. Add the following code segment to the Page_Load method of the page code-behind file.
CustomMaster custom = this.Master as CustomMaster;
lblRegion.Text = custom.Region;
C. Add the following code segment to the Page_Load method of the Custom.Master.cs code-behind file.
Label lblRegion = Page.FindControl("lblRegion") as Label; lblRegion.Text = this.Region;
D. Add the following code segment to the Page_Load method of the Custom.Master.cs code-behind file.
Label lblRegion = Master.FindControl("lblRegion") as Label; lblRegion.Text = this.Region;
 
Which is the correct one?.
I have confusion between A & B
Posted 9-Jan-13 1:06am
Tejal S1.9K

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

The right answer is B because this.Master would give you access to the master page whereas this.Parent would give you access to the parent class of the page which would be System.Web.UI.Control (i think). To access whats defined in Master page this.Master is used.
  Permalink  
Comments
Member 9725940 at 9-Jan-13 6:52am
   
Thank You sir :)
Aman.A at 9-Jan-13 7:15am
   
cheers!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 DamithSL 405
1 OriginalGriff 245
2 Sergey Alexandrovich Kryukov 207
3 Peter Leow 185
4 Afzaal Ahmad Zeeshan 154
0 OriginalGriff 7,460
1 DamithSL 5,519
2 Sergey Alexandrovich Kryukov 4,954
3 Maciej Los 4,936
4 Kornfeld Eliyahu Peter 4,514


Advertise | Privacy | Mobile
Web04 | 2.8.141223.1 | Last Updated 9 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100