user control load event does not fire on postback

  • Thread starter Thread starter Marcel Balcarek
  • Start date Start date
M

Marcel Balcarek

I create a user control dynamically:
Dim newCriteriaControl As CriteriaTextBoxUserControl =
CType(Me._page.LoadControl("CriteriaTextBoxUserControl.ascx"),
CriteriaTextBoxUserControl)

myContainer.Add(newCriteriaControl)

and the user control's load event executes on initial executon of the page.
On a POST of the same page, the control is added as above, but the load
event is not firing, nor is prerender.

What's going on? How can I get code to execute in the user control on a page
postback?

Marcel
 
Hi Marcel Balcarek,

I have Tried to reproduce your problem but am not facing any problems. i
have created one usercontrol and am dynamically adding it in the page load
event of the page and the event is getting fired for me.

you may check this code if you are missing something.

UserControls' Page Load
if (Page.IsPostBack)
{
Response.Write("This is a PostBack... haahaah")
}
else
{
Response.Write("This is not a PostBack...")
}

Page's Page_Load
Dim myControl As CriteriaTextBoxUserControl =
CType(Me.LoadControl("CriteriaTextBoxUserControl.ascx"),
CriteriaTextBoxUserControl)
PlaceHolder1.Controls.Add(myControl)

PS: also check that you are not missing to add the user control in the
page_load's Postback.

Regards
Ashish M Bhonkiya
 
Back
Top