UpdatePanel 完整回发
您好,这是场景。
我有一个带有 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>
因此,当我单击“linkButton”时,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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您正在手动触发 UpdatePanel 不知道的事件。 您需要将该事件绑定到您的控件并注册它:
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:
我很好奇removeLastLoadedControl() 方法中发生了什么。
I'm curious as to what is going on within the removeLastLoadedControl() method.