Question:
You create a Microsoft ASP.NET application by using the Microsoft .NET Framework version 3.5. You write the following code fragment to create a user control named UserCtrl.ascx.
< %@ Control Language="C#" AutoEventWireup="true"
CodeFile="UserCtrl.ascx.cs" Inherits="UserCtrl" % >
< %@ OutputCache Duration="10" VaryByParam="None" % > < script runat="ser ver" >
public string MyStatusText
{
get{return LblStatus.Text;}
set{LblStatus.Text = value;}
}
< /script >
< asp:Label ID="LblStatus" runat="server" / >
You create a Web page named Default.aspx.
You need to add the UserCtrl.ascx user control to the Default.aspx page dynamically. You also need to set the MyStatusText property to the value "Welcome". Which code segment should you add to the Default.aspx page?
A
UserCtrl ctrl = LoadControl("UserCtrl.ascx") as UserCtrl; this.Controls.Add(ctrl);
if (ctrl != null)
{
ctrl.MyStatusText = "Welcome";
}
B
UserCtrl ctrl = LoadControl("UserCtrl.ascx") as UserCtrl; this.Controls.Add(ctrl);
if (ctrl.CachePolicy!=null)
{
ctrl.MyStatusText = "Welcome";
}
PartialCachingControl ctrl = LoadControl("UserCtrl.ascx") as PartialCachingControl; this.Controls.Add(ctrl);
if (ctrl.CachedControl != null)
{
C
UserCtrl uc = ctrl.CachedControl as UserCtrl;
uc.MyStatusText = "Welcome";
}
PartialCachingControl ctrl = LoadControl("UserCtrl.ascx") as PartialCachingControl; this.Controls.Add(ctrl);
if (ctrl.CachePolicy!=null)
{
D
UserCtrl uc = ctrl.Parent as UserCtrl;
uc.MyStatusText = "Welcome";
}
+ AnswerC
+ Report