user control load event does not fire on postback

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
 
A

Ashish M Bhonkiya

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
 

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,769
Messages
2,569,581
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top