Question:
You create a Microsoft ASP.NET application by using the Microsoft .NET Framework version 3.5. You create two user controls named UserCtrlA.ascx and UserCtrlB.ascx. The user controls postback to the server. You create a new Web page that has the following ASPX code.
<asp:CheckBox ID="Chk" runat="server"
oncheckedchanged="Chk_CheckedChanged" AutoPostBack="true" /> <asp:PlaceHolder ID="PlHolder" runat="server"></asp:PlaceHolder> To dynamically create the user controls, you write the following code segment for the Web page.
public void LoadControls()
{
if (ViewState["CtrlA"] != null)
{
Control c;
if ((bool)ViewState["CtrlA"] == true)
{ c = LoadControl("UserCtrlA .ascx"); }
else
{ c = LoadControl("UserCtrlB.ascx"); }
A
ID = "Ctrl";
PlHolder.Controls.Add(c);
}
}
protected void Chk_CheckedChanged(object sender, EventArgs e) {
ViewState["CtrlA"] = Chk.Checked;
PlHolder.Controls.Clear();
LoadControls();
}
B
protected override object SaveViewState()
{
LoadControls();
return base.SaveViewState();
}
C
protected override void Render(HtmlTextWriter writer) {
LoadControls();
base.Render(writer);
}
D
protected override void OnLoadComplete(EventArgs e)
{
base.OnLoadComplete(e);
LoadControls();
}
E
protected override void LoadViewState(object savedState) {
base.LoadViewState(savedState);
LoadControls();
}
+ AnswerD
+ Report