asp.net - 取消跨页回发?

标签 asp.net asp.net-ajax asp.net-2.0 cross-page-postback

我有一个页面有几个 ListBox使用 AutoPostBack 基于所选值进行级联过滤的 es .该表单采用所有选定的值,并通过跨页发布到不同的 ASPX 来生成 excel 文档。问题是,单击提交一次后,每次选择更改时,它都会不断触发跨页面回发。

<asp:ScriptManager runat="server" />
<asp:UpdatePanel UpdateMode="Conditional" runat="server">
    <ContentTemplate>
  <asp:ListBox ID="ParentItems" runat="server" SelectionMode="Multiple" AutoPostBack="true"></asp:ListBox>    
  <asp:ListBox ID="ChildItems" runat="server" SelectionMode="Multiple" AutoPostBack="true"></asp:ListBox>  
 </ContentTemplate>
</asp:UpdatePanel>

<asp:Button ID="Submit" runat="server" PostBackUrl="~/AnotherPageThatGeneratesAnExcelDoc.aspx" />

如何从 ListBox 取消跨页回发es' SelectedIndexChanged事件?

这是代码隐藏中的事件:
Protected Sub ParentItems_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ParentItems.SelectedIndexChanged
 '' do some filtering of the ChildItems ListBox

 '' tried these but they do not work
 ''Submit.Enabled = False

 ''Submit.PostBackUrl = String.Empty

 '' I also tried wrapping the button in a PlaceHolder and hiding/removing it, neither worked
 ''Buttons.Visible = False
 ''Buttons.Controls.Remove(Submit)
End Sub

最佳答案

这是我目前使用 javascript 的解决方案。它有效,但似乎是一个黑客:

// using jQuery, add a click event that resets the form action
$("select[multiple]").click(function () {
    this.form.action = this.form._initialAction;
});

编辑:在代码隐藏中添加一个点击事件:
ParentItems.Attributes("onclick") = "this.form.action = this.form._initialAction;"

关于asp.net - 取消跨页回发?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4472591/

相关文章:

c# - VS2010 奇怪的 ASP.NET 启动错误

javascript - 动态表单,Microsoft JScript 运行时错误 : 'b' is null or not an object

asp.net - 为什么设置 @Page masterPageFIle 时不隐含 @MasterType 指令?

c# - Convert.ToDateTime DD :HH:mm:ss C#/ASP. 净 GridView RowDataBound

.net - 如何使 HttpContext 可供我的单元测试使用?

c# - DetailsView 的事件 "ItemUpdating"中的 OldValues 集合始终为空

javascript - 将参数从客户端传递到服务器端

c# - 在 ASP.NET 中使用 Masked Edit Extender 的 TextBox 中的退格键或删除键在 Chrome 中不起作用

asp-classic - 经典的asp/asp.net网站-global.asa无法正常工作

vb.net - 导出到 Excel