Все UpdatePanels при обновлении страницы на __doPostBack - PullRequest
1 голос
/ 04 января 2012

Я испытываю неактивное поведение при попытке обновить UpdatePanel с помощью JavaScript, когда на странице есть несколько UpdatePanels.

Постараюсь сделать его коротким:

  • Я ужеустановив для параметра UpdateMode значение Conditional
  • Я передаю правильный ClientID панели обновления в __EventTarget
  • В коде позади я успешно могу найти целевой элемент управления

Но по какой-то причине OnLoad каждой UpdatePanel на странице запускается.

Ниже приведен фрагмент кода - есть идеи, почему это происходит?

Ascx:

<div class="updatePanelWrapper">
<asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional" RenderMode="Inline" OnLoad="UpdatePanel1Load"
    runat="server">
    <ContentTemplate>
        <asp:Panel ID="Panel1" runat="server">
        </asp:Panel>
    </ContentTemplate>
</asp:UpdatePanel>
</div>
<div class="updatePanelWrapper">
<asp:UpdatePanel ID="UpdatePanel2" UpdateMode="Conditional" RenderMode="Inline" OnLoad="UpdatePanel2Load"
    runat="server">
    <ContentTemplate>
        <div>
            <asp:Panel ID="Panel2" runat="server">
            </asp:Panel>
        </div>
    </ContentTemplate>
</asp:UpdatePanel>
</div>

CodeBehind:

protected void UpdatePanel1Load(object sender, EventArgs e)
{
    UpdatePanelLoad(sender, e);
}

protected void UpdatePanel2Load(object sender, EventArgs e)
{
    UpdatePanelLoad(sender, e);
}

protected void UpdatePanelLoad(object sender, EventArgs e)
{
    // if only a async postback then load the control
    if (ScriptManager.GetCurrent(Page).IsInAsyncPostBack)
    {
        // Some Logic ...
    }
}

JavaScript (где я запускаю ASYNC PostBack):

var updatePanelWrappers = $(".updatePanelWrapper");
var availableWrapper = updatePanelWrappers[0];
var updatePanelElement = $(availableWrapper).children()[0];
var updatePanelId = $(updatePanelElement).attr("id");

window.__doPostBack(updatePanelId, "Some Arguments...");

1 Ответ

0 голосов
/ 04 января 2012

С обратным вызовом UpdatePanel страница все еще проходит большую часть своего жизненного цикла;который включает в себя все события загрузки.

...