Reputation: 41
I dynamically load a User Control
, with an Update Panel
inside a Place Holder
.
When I click a button from the User Control
, should refresh the Update Panel
contents, but it refresh the entire page instead, and the User Control is disappearing from the page, because the page's Page_Load
does not load anything if it's a PostBack
.
How I can fix it?
Upvotes: 1
Views: 2341
Reputation: 1817
You need to add the control page to the page in the page_init method. It has to be added on each post back. The control will retain all the values even after adding it back.
There is a full working example at this link.
Upvotes: 0
Reputation: 3235
Whenever a partial or full postback happen , Automatically all update() method of all updatepanels fire . For preventing such this behavior you need to set UpdateMode="Conditional"
property . In this situation you need to specify asynchronous trigger
Or ChildrenAsTriggers=true
.
for preventing a dynamically loaded-usercontrol to be disappear ,It's good to save it in ViewState , Here is a tutorial and sample application
Upvotes: 2
Reputation: 4244
Make sure you are creating the control EVERY page request, regardless of GET/POST. Also, make sure you are giving it the same ID.
I like to override the CreateChildControls method.
Upvotes: 0
Reputation: 517
I think you'll need to reinject the control in page_load or pre_render. Dynamically created controls don't live through postback.
Upvotes: 0