Usercontrol in Page_Load

B

Big Charles

Hello,

I don't know how UserControl should work:

If I put MyPlaceHolder.Controls.Add(MyUsrControl) inside "If (Not
Page.IsPostBack) Then", when MyWebForm is loaded, the usercontrol is
not loaded.
Why not?

Example:

Public Class MyWebForm
Inherits System.Web.UI.Page

Private MyUsrControl As Control =
LoadControl("../myUsrControl.ascx")

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

If (Not Page.IsPostBack) Then
MyPlaceHolder.Controls.Add(MyUsrControl) ' Does not work.
Why?
End If

MyPlaceHolder.Controls.Add(MyUsrControl) ' Here it works
End Sub
 
?

=?ISO-8859-1?Q?G=F6ran_Andersson?=

You have to add the control to the page every time, not just the first
time the page is loaded.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,736
Latest member
AdolphBig6

Latest Threads

Top