473,545 Members | 1,998 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.as px.vb

Public Class PageLoadTest

Inherits System.Web.UI.P age

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.

<System.Diagnos tics.DebuggerSt epThrough()> Private Sub
InitializeCompo nent()

End Sub

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

'Do not delete or move it.

Private designerPlaceho lderDeclaration As System.Object

Protected WithEvents Button1 As System.Web.UI.W ebControls.Butt on

Protected WithEvents ph1 As System.Web.UI.W ebControls.Plac eHolder

Protected WithEvents ph2 As System.Web.UI.W ebControls.Plac eHolder

Protected WithEvents crpersontype1 As CRPersonType

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

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

'Do not modify it using the code editor.

InitializeCompo nent()

Dim ctrl, ctrl2 As UserControl

If Not Page.IsPostBack Then

ctrl = New UserControl

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

ctrl.ID = "crTest1"

Session("PageLo adTest_ctrl") = ctrl

ctrl2 = New UserControl

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

ctrl2.ID = "crTest2"

Session("PageLo adTest_ctrl2") = ctrl2

ph1.Controls.Cl ear()

ph1.Controls.Ad d(ctrl)

ph2.Controls.Cl ear()

ph2.Controls.Ad d(ctrl2)

Else

ctrl = CType(Session(" PageLoadTest_ct rl"), test)

ctrl2 = CType(Session(" PageLoadTest_ct rl2"), test2)

ph1.Controls.Cl ear()

ph1.Controls.Ad d(ctrl)

ph2.Controls.Cl ear()

ph2.Controls.Ad d(ctrl2)

End If

End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) 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.U serControl

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.

<System.Diagnos tics.DebuggerSt epThrough()> Private Sub
InitializeCompo nent()

End Sub

Protected WithEvents DataGrid1 As System.Web.UI.W ebControls.Data Grid

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

'Do not delete or move it.

Private designerPlaceho lderDeclaration As System.Object

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

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

'Do not modify it using the code editor.

InitializeCompo nent()

End Sub

#End Region

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

'Put user code to initialize the page here

Trace.Write("te st.ascx pageload()")

End Sub

End Class
Test2.ascx.vb:

Public Class test2

Inherits BaseClientCente rUserControl

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.

<System.Diagnos tics.DebuggerSt epThrough()> Private Sub
InitializeCompo nent()

End Sub

Protected WithEvents TextBox1 As System.Web.UI.W ebControls.Text Box

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

'Do not delete or move it.

Private designerPlaceho lderDeclaration As System.Object

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

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

'Do not modify it using the code editor.

InitializeCompo nent()

End Sub

#End Region

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

'Put user code to initialize the page here

Trace.Write("te st2.ascx pageload()")

End Sub

End Class

Nov 19 '05 #1
0 2270

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

Similar topics

5
7891
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 the web user controls is one assembly though the Page_Init is fired. The Page_Load has the "Handles MyBase.Load" but still, when I step through...
2
11383
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 using them. My aspx page is simple: <%@ Register TagPrefix="TestPoll" TagName="Message" Src="poll.ascx" %> .... <form id="Form1" method="post"...
3
2551
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 details, their locations, and then add themselves to categories. Each category requires additional info from the suppliers, this additional category info...
2
3182
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 textbox. I also have a CompareValidator pointed to the textbox with its Type="Date." Despite all documentation to the contrary, I am getting an...
14
13093
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) { //existing session? if (Session == null) { //save local empty order object this._newOrder = Orders.Initialize();
2
1482
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 logout button on one of the user controls which takes the user back to the login screen. If the user tries to log in again without closing the browser...
1
3108
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 example, is clicked, after Page_Load the button's click event is also fired. Since session is abandoned at this moment, any object references raise
1
2214
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 into catalog mode, and put the selected controls (ascx) into a webzone and viola, the controls are there, but the user control page_load thinks it's...
2
2400
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 answer dialog. The user answers a question, and the next subquestion appears (using dynamic html display:none|block) depending on his answer.
0
7473
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7406
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7813
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7761
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5337
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4949
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3444
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1020
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
709
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.