UpdatePanel 完整回发

发布于 2024-07-18 17:01:44 字数 2326 浏览 2 评论 0原文

您好,这是场景。

我有一个带有 updatepanel 的 .aspx 页面,

<asp:UpdatePanel id="uPanelMain" runat="server">
    <ContentTemplate>
        <uc:Calendar id="ucCalendar" runat="server" Visible="true" />
       <uc:Scoring id="ucScoring" runat="server" Visible="false" />
   </ContentTemplate>

首先加载控件 ucCalendar,它包含一个像这样的网格

<asp:DataGrid CssClass="grid" ID="gridGames" runat="server" AutoGenerateColumns="False" HeaderStyle-CssClass="gridHeader" ItemStyle-CssClass="gridScoringRow"  
            GridLines="None" ItemStyle-BackColor="#EEEEEE" AlternatingItemStyle-BackColor="#F5F5F5"
            OnEditCommand="doScoreGame" OnDeleteCommand="doEditGame" OnCancelCommand="printLineup" OnItemDataBound="gridDataBound">
   <Columns>
        <asp:TemplateColumn >
            <ItemTemplate>
                <asp:CheckBox ID="chkDelete" runat="server" />
            </ItemTemplate>
        </asp:TemplateColumn>
        <asp:BoundColumn DataField="idGame" Visible="false" />
        <asp:BoundColumn DataField="isClose" Visible="false" />
        <asp:TemplateColumn HeaderText="Status">
            <ItemTemplate>
                <asp:Image ID="imgStatus" runat="server" ImageUrl="~/img/icoX.png" alt="icoStatus" />
            </ItemTemplate>
        </asp:TemplateColumn>
        <asp:TemplateColumn>
            <ItemTemplate>
                <asp:LinkButton ID="linkScore" runat="server" CommandName="Edit" Text="Score" />
            </ItemTemplate>
        </asp:TemplateColumn>
   </Columns>
</asp:DataGrid>

因此,当我单击“linkBut​​ton”时,userControl 的代码隐藏调用 .aspx 中的公共方法,如下所示

: userControl

    protected void doScoreGame(object sender, DataGridCommandEventArgs e)
    {
        ((GM)this.Page).showScoring(null, null);
    }

来自 .aspx 页面

public void showScoring(object sender, EventArgs e)
{
    removeLastLoadedControl();
    ucScoring.Visible = true;
}

因此,问题来了:

当我更改 ucScoring 控件的可见属性时,会发生两次回发。

第一次回发很好,它由 updatePanel 处理。

第二次回发是完整的回发,我真的不明白为什么会发生这种情况。

我真的迷路了,请帮忙!

谢谢马特

Greetings, here is the scenario.

I have and .aspx page with and updatepanel like this

<asp:UpdatePanel id="uPanelMain" runat="server">
    <ContentTemplate>
        <uc:Calendar id="ucCalendar" runat="server" Visible="true" />
       <uc:Scoring id="ucScoring" runat="server" Visible="false" />
   </ContentTemplate>

The control ucCalendar is loaded first and it contains a grid like this

<asp:DataGrid CssClass="grid" ID="gridGames" runat="server" AutoGenerateColumns="False" HeaderStyle-CssClass="gridHeader" ItemStyle-CssClass="gridScoringRow"  
            GridLines="None" ItemStyle-BackColor="#EEEEEE" AlternatingItemStyle-BackColor="#F5F5F5"
            OnEditCommand="doScoreGame" OnDeleteCommand="doEditGame" OnCancelCommand="printLineup" OnItemDataBound="gridDataBound">
   <Columns>
        <asp:TemplateColumn >
            <ItemTemplate>
                <asp:CheckBox ID="chkDelete" runat="server" />
            </ItemTemplate>
        </asp:TemplateColumn>
        <asp:BoundColumn DataField="idGame" Visible="false" />
        <asp:BoundColumn DataField="isClose" Visible="false" />
        <asp:TemplateColumn HeaderText="Status">
            <ItemTemplate>
                <asp:Image ID="imgStatus" runat="server" ImageUrl="~/img/icoX.png" alt="icoStatus" />
            </ItemTemplate>
        </asp:TemplateColumn>
        <asp:TemplateColumn>
            <ItemTemplate>
                <asp:LinkButton ID="linkScore" runat="server" CommandName="Edit" Text="Score" />
            </ItemTemplate>
        </asp:TemplateColumn>
   </Columns>
</asp:DataGrid>

So when i click the "linkButton", the codebehind of the userControl calls a public method in the .aspx as this:

From the userControl

    protected void doScoreGame(object sender, DataGridCommandEventArgs e)
    {
        ((GM)this.Page).showScoring(null, null);
    }

From the .aspx page

public void showScoring(object sender, EventArgs e)
{
    removeLastLoadedControl();
    ucScoring.Visible = true;
}

So, here comes the problem:

There are two postbacks taking place when I change the visible attribute of the ucScoring control.

The first postback is fine, it's handled by the updatePanel.

The second postback is a full postback, and i really don't understand why it is happening.

I'm really lost here, please help!

Thanks

Mat

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

带上头具痛哭 2024-07-25 17:01:44

您正在手动触发 UpdatePanel 不知道的事件。 您需要将该事件绑定到您的控件并注册它:

ScriptManager.RegisterAsyncPostBack(ucScoring);

You are firing an event manually that the UpdatePanel does not know about. You will need to tie that event to your control and register it:

ScriptManager.RegisterAsyncPostBack(ucScoring);
帅哥哥的热头脑 2024-07-25 17:01:44

我很好奇removeLastLoadedControl() 方法中发生了什么。

I'm curious as to what is going on within the removeLastLoadedControl() method.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文