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
 
Ad

Advertisements

?

=?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

Top