双击列表框时引发异步回发
我有一个 ASP.NET 列表框,lstActivities
。要编辑列表中的项目,用户可以单击 lnkButton
或双击列表框。我通过以下方式实现此目的:
protected void Page_Load(object sender, EventArgs e) {
if (IsPostBack) return;
var refDblClick = ClientScript.GetPostBackEventReference(lnkButton, "dblClick");
lstActivities.Attributes.Add("ondblclick", refDblClick);
}
protected override void Render(HtmlTextWriter writer)
{
ClientScript.RegisterForEventValidation(lnkButton.UniqueID, "dblClick");
base.Render(writer);
}
我想更改此设置,以便使用 AJAX 异步回发。目前,列表框和按钮位于 UpdatePanel 中,因此单击按钮时会发生异步回发。但是当双击列表框时,会发生完整的回发。
<asp:UpdatePanel ID="up" UpdateMode="Conditional" ChildrenAsTriggers="true"
runat="server">
<ContentTemplate>
<asp:ListBox ID="lstActivities" runat="server"></asp:ListBox>
<asp:LinkButton ID="lnkButton" runat="server" OnClick="lnkButton_Click">
Edit</asp:LinkButton>
</ContentTemplate>
</asp:UpdatePanel>
如何让双击只刷新UpdatePanel?
I have an ASP.NET listbox, lstActivities
. To edit an item in the list, users can either click lnkButton
or double-click on the listbox. I achieve this with:
protected void Page_Load(object sender, EventArgs e) {
if (IsPostBack) return;
var refDblClick = ClientScript.GetPostBackEventReference(lnkButton, "dblClick");
lstActivities.Attributes.Add("ondblclick", refDblClick);
}
protected override void Render(HtmlTextWriter writer)
{
ClientScript.RegisterForEventValidation(lnkButton.UniqueID, "dblClick");
base.Render(writer);
}
I would like to change this so that the postback is asynchronous, using AJAX. At the moment, the listbox and button are in an UpdatePanel so there is an async postback when the button is clicked. But when the listbox is double-clicked, a full postback occurs.
<asp:UpdatePanel ID="up" UpdateMode="Conditional" ChildrenAsTriggers="true"
runat="server">
<ContentTemplate>
<asp:ListBox ID="lstActivities" runat="server"></asp:ListBox>
<asp:LinkButton ID="lnkButton" runat="server" OnClick="lnkButton_Click">
Edit</asp:LinkButton>
</ContentTemplate>
</asp:UpdatePanel>
How can I make the double-click refresh only the UpdatePanel?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
有几件事可以尝试:
或者
A few things to try:
or
我只是使用您提供的代码进行了快速测试,并且在单击按钮和双击列表时确实得到了“部分回发”(因为缺乏更好的术语,因为 updatepanels 总是进行完整回发)。
如果您将该页面中的其他面板设置为
UpdateMode="Conditional"
,就像您对 UpdatePanel“up”所做的那样,则只有“up”内的元素才会更新。如果您没有在其他面板上指定更新模式,那么它们将始终在回发时更新,因为更新面板始终执行完整回发;他们真正做的是部分刷新页面。我认为链接有关 UpdatePanel 的 MSDN 文档是非常有帮助的阅读。
I just a ran a quick test with the code you provided and I do get "partial postbacks" (for lack of a better term since updatepanels always do full postbacks) on both, the clicking of the button and the double clicking of the list.
If you set other panels in that page to
UpdateMode="Conditional"
as you are doing with your UpdatePanel "up", then only elements inside "up" will be updated. If you don't specify the update mode on the other panels, then they will always be updated on postback, because, again, update panels ALWAYS do full postbacks; what they really do is partial refreshes of the page.Linking MSDN documentation regarding UpdatePanel as I think is a very helpful read.
我尝试了建议的解决方案,但没有运气。这是一个相当复杂的页面,有很多 UpdatePanel,因此很难解决确切的问题。
最后我选择了 jQuery:
I tried the solutions suggested, but with no luck. It's quite a complicated page with lots of UpdatePanels so hard to work out the exact problem.
In the end I went for jQuery: