PrepAway - Latest Free Exam Questions & Answers

Which code segment should you use?

You need to dynamically add TestUserControl.ascx to TestPage.aspx. Which code segment should
you use?

PrepAway - Latest Free Exam Questions & Answers

A.
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim userControl As Control = Page.LoadControl(“TestUserControl.ascx”)
Page.Form.Controls.Add(userControl)
End Sub

B.
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim userControl As Control = Page.FindControl(“TestUserControl.ascx”)
Page.Form.Controls.Add(userControl)
End Sub

C.
Private Sub TestPage_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
Dim userControl As Control = Page.LoadControl(“TestUserControl.ascx”)
Page.Form.Controls.Add(userControl)
End Sub

D.
Private Sub TestPage_PreInit(ByVal sender As Object, ByVal e As System.EventArgs) Handles
Me.PreInit
Dim userControl As Control =
Page.FindControl(“TestUserControl.ascx”Page.Form.Controls.Add(userControl) End Sub

Explanation:
Dynamic controls should be added in preinit event for them to participate in view state. Check
description of preinit and init events on page-105 of Microsoft Press book MCTS 70-515.


Leave a Reply