【问题标题】:UserControl, PlaceHolder and UpdatePanel On PostBackPostBack 上的 UserControl、PlaceHolder 和 UpdatePanel
【发布时间】:2011-03-13 19:37:57
【问题描述】:

我动态加载一个User Control,在Place Holder 内有一个Update Panel

当我单击User Control 中的按钮时,应该刷新Update Panel 内容,但它会刷新整个页面,并且用户控件从页面中消失,因为页面的Page_Load 没有加载任何内容如果是PostBack

我该如何解决?

【问题讨论】:

    标签: asp.net updatepanel user-controls placeholder


    【解决方案1】:

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

    为了防止动态加载的用户控件消失,最好保存在 ViewState 中,Here is a tutorial and sample application

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        【解决方案3】:

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

        我喜欢重写 CreateChildControls 方法。

        【讨论】:

          【解决方案4】:

          需要在page_init方法中将控制页面添加到页面中。它必须添加到每个帖子后面。即使添加回来,控件也会保留所有值。

          There is a full working example at this link.

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 2014-05-03
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2010-12-30
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多