Which method should you add to the Web page?

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 Sub LoadControls()
If ViewState("CtrlA") IsNot Nothing Then

Dim c As Control
If CBool(ViewState("CtrlA")) = True Then
c = LoadControl("UserCtrlA.ascx")
Else
c = LoadControl("UserCtrlB.ascx")
End If

c.ID = "Ctrl"
PlHolder.Controls.Add(c)
End If

End Sub

Protected Sub Chk_CheckedChanged(sender As Object, e As EventArgs)
ViewState("CtrlA") = Chk.Checked
PlHolder.Controls.Clear()
LoadControls()
End Sub

You need to ensure that the user control that is displayed meets the following requirements:
It is recreated during postback It retains its state.
Which method should you add to the Web page?

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 Sub LoadControls()
If ViewState("CtrlA") IsNot Nothing Then

Dim c As Control
If CBool(ViewState("CtrlA")) = True Then
c = LoadControl("UserCtrlA.ascx")
Else
c = LoadControl("UserCtrlB.ascx")
End If

c.ID = "Ctrl"
PlHolder.Controls.Add(c)
End If

End Sub

Protected Sub Chk_CheckedChanged(sender As Object, e As EventArgs)
ViewState("CtrlA") = Chk.Checked
PlHolder.Controls.Clear()
LoadControls()
End Sub

You need to ensure that the user control that is displayed meets the following requirements:
It is recreated during postback It retains its state.
Which method should you add to the Web page?

A.
Protected Overrides Function SaveViewState() As Object
LoadControls()
Return MyBase.SaveViewState()
End Function

B.
Protected Overrides Sub Render(writer As HtmlTextWriter)
LoadControls()
MyBase.Render(writer)
End Sub

C.
Protected Overrides Sub OnLoadComplete(e As EventArgs)
MyBase.OnLoadComplete(e)
LoadControls()
End Sub

D.
Protected Overrides Sub LoadViewState(savedState As Object)
MyBase.LoadViewState(savedState)
LoadControls()
End Sub



Leave a Reply 0

Your email address will not be published. Required fields are marked *