473,388 Members | 1,417 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

Page_Load not firing for SIMPLE Dynamic User Controls

I am having a problem where the page load event is not being fired
for certain user controls that I load dynamically in placeholders.
Here is what I'm doing in brief, with full test code supplied at the
bottom.

In my controlling .aspx page, in the page_init() sub, if not postback,
I load two user controls and place them in placeholders. This works
and a trace statement in each user control's page load handler is
executed on initial page load. Then, using a basic button in the
..aspx, I post back the page. At this point, page_load runs only in one
of the user controls. The weird thing here is that these usercontrols
are identical except that one has a datagrid control in it and the
other has a label control in it. If I remove the datagrid control from
the control where page_load always runs, it stops working; conversely,
if I add it to the other user control, page_load now runs on every
postback.

I am storing each usercontrol in session and retrieving and reinserting
it on postback (not by my design), but I would think that if this was
the problem, page_load wouldn't fire on postback for either
usercontrol. Also, autoeventwireup is set to false for all components.

Can any of you gurus help me out here?

Thanks,
Jelling

Full Code, minus the html I couldn't paste in.

PageLoadTest.aspx.vb

Public Class PageLoadTest

Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.

<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()

End Sub

'NOTE: The following placeholder declaration is required by the Web
Form Designer.

'Do not delete or move it.

Private designerPlaceholderDeclaration As System.Object

Protected WithEvents Button1 As System.Web.UI.WebControls.Button

Protected WithEvents ph1 As System.Web.UI.WebControls.PlaceHolder

Protected WithEvents ph2 As System.Web.UI.WebControls.PlaceHolder

Protected WithEvents crpersontype1 As CRPersonType

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init

'CODEGEN: This method call is required by the Web Form Designer

'Do not modify it using the code editor.

InitializeComponent()

Dim ctrl, ctrl2 As UserControl

If Not Page.IsPostBack Then

ctrl = New UserControl

ctrl = Page.LoadControl("~/clientcenter/user/test.ascx")

ctrl.ID = "crTest1"

Session("PageLoadTest_ctrl") = ctrl

ctrl2 = New UserControl

ctrl2 = Page.LoadControl("~/ClientCenter/User/test2.ascx")

ctrl2.ID = "crTest2"

Session("PageLoadTest_ctrl2") = ctrl2

ph1.Controls.Clear()

ph1.Controls.Add(ctrl)

ph2.Controls.Clear()

ph2.Controls.Add(ctrl2)

Else

ctrl = CType(Session("PageLoadTest_ctrl"), test)

ctrl2 = CType(Session("PageLoadTest_ctrl2"), test2)

ph1.Controls.Clear()

ph1.Controls.Add(ctrl)

ph2.Controls.Clear()

ph2.Controls.Add(ctrl2)

End If

End Sub

#End Region

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

'Put user code to initialize the page here
End Sub
End Class


Test.ascx.vb:
Public Class test

Inherits System.Web.UI.UserControl

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.

<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()

End Sub

Protected WithEvents DataGrid1 As System.Web.UI.WebControls.DataGrid

'NOTE: The following placeholder declaration is required by the Web
Form Designer.

'Do not delete or move it.

Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init

'CODEGEN: This method call is required by the Web Form Designer

'Do not modify it using the code editor.

InitializeComponent()

End Sub

#End Region

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

'Put user code to initialize the page here

Trace.Write("test.ascx pageload()")

End Sub

End Class
Test2.ascx.vb:

Public Class test2

Inherits BaseClientCenterUserControl

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.

<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()

End Sub

Protected WithEvents TextBox1 As System.Web.UI.WebControls.TextBox

'NOTE: The following placeholder declaration is required by the Web
Form Designer.

'Do not delete or move it.

Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init

'CODEGEN: This method call is required by the Web Form Designer

'Do not modify it using the code editor.

InitializeComponent()

End Sub

#End Region

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

'Put user code to initialize the page here

Trace.Write("test2.ascx pageload()")

End Sub

End Class

Nov 19 '05 #1
0 2250

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Brad | last post by:
I have web user controls (ascx files) in multiple support assemblies; I'm building on a Commerce Server SDK sample. My problem is that the code behind Page_Load event is never getting called for...
2
by: C K | last post by:
I am having trouble getting the page_load event to fire from within my usercontrol - my code is below, I'm sure I'm missing something simple. Just your basic web user control - I've just began...
3
by: Tim Thomas | last post by:
Hi, I am very new to .NET and am in the process of building my first web application. I will briefly describe what i am trying to achieve: I have a system where suppliers register their...
2
by: Eric Maia | last post by:
I have a textbox (StartDateTextBox) in a UserControl on my page, that is supposed to have a date entered into it. I have a RequiredFieldValidator that has its ControlToValidate property set to the...
14
by: V. Jenks | last post by:
I'm a little rusty having not touched .NET for 6 months and I can't remember why Page_Load is happening twice in this code: private void Page_Load(object sender, System.EventArgs e) {...
2
by: mollyf | last post by:
I have a web application where I have my users log in and it takes them to default.aspx. On that page, I have 2 user controls. Everything works fine the first time a person logs in. I have a...
1
by: Ahmet Gunes | last post by:
Hi all, I check whether session is alive in Page_Load. If session is not alive then I want to navigate to another page, most probably the login page. But when a control, a button for...
1
by: ryan.mclean | last post by:
Hello all, Here is my problem: I made a simple web project that uses they new webparts. On my page, I have a DeclarativeCatalogPart that contains references to several ascx files. I put my page...
2
by: brad | last post by:
Group, I'm using Visual Studio 2003 to create an ASP.NET 1.1 project which contains nested server user controls in order to create a tree-like hierarchy. The tree is a sort of question and...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.