1

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?

4

4 回答 4

2

每当发生部分或全部回发时,所有更新面板的所有 update() 方法都会自动触发。为了防止这种行为,您需要设置UpdateMode="Conditional"property 。在这种情况下,您需要指定asynchronous triggerOr ChildrenAsTriggers=true

为了防止动态加载的用户控件消失,最好将其保存在 ViewState 中, 这是一个教程和示例应用程序

于 2011-10-28T23:05:48.553 回答
0

我认为您需要在 page_load 或 pre_render 中重新注入控件。动态创建的控件不能通过回发来实现。

于 2010-07-09T11:13:21.313 回答
0

确保您正在创建控件每个页面请求,无论 GET/POST 是什么。另外,请确保您为其提供相同的 ID。

我喜欢重写 CreateChildControls 方法。

于 2010-07-09T12:49:05.817 回答
0

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.

于 2016-02-09T19:51:36.950 回答