UserControl导致完全回发

时间:2012-07-10 07:31:35

标签: asp.net user-controls updatepanel

我在更新面板中有占位符。在Page_Load上,我通过以下代码加载用户控件:

Control ctrl = LoadControl("~/UserControls/ListViewThumbs.ascx");
ucThumbs = (ListViewThumbs)ctrl;
ucThumbs.ID = "ucThumbs";


ucThumbs.SelectedIndexChanged += new UserControlSelectedIndexChanged(listView_SelectedIndexChanging);
ucThumbs.ItemDoubleClicked += new UserControlItemDoubleClicked(UserControlDoubleClicked);

ucPH.Controls.Clear();
ucPH.Controls.Add(ucThumbs);


AsyncPostBackTrigger trigger = new AsyncPostBackTrigger();
trigger.ControlID = ucThumbs.UniqueID;
trigger.EventName = "ItemDoubleClicked";
updateMyDocs.Triggers.Add(trigger);

在aspx代码下面:

<asp:UpdatePanel ID="updateMyDocs" UpdateMode="Always" ChildrenAsTriggers = "true" EnableViewState = "true" runat="server">
<ContentTemplate>
    <asp:PlaceHolder ID="ucPH" runat="server"></asp:PlaceHolder>
</ContentTemplate>

单击usercontrol会导致完全回发。我该如何预防?

1 个答案:

答案 0 :(得分:0)

我会将更新面板放在userControl中而不是在其外部。

当您将UserControls放入其中时,更新面板会出现类似的问题