加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net – 取消跨页回发?

发布时间:2020-12-16 09:34:12 所属栏目:asp.Net 来源:网络整理
导读:我有一个页面有几个ListBox,它们使用AutoPostBack基于所选值进行一些级联过滤.表单采用所有选定的值,并通过跨页面发布到不同的ASPX生成Excel文档.问题是,在单击提交一次后,每次选择更改时,它将不断触发跨页回发. asp:ScriptManager runat="server" /asp:Upda
我有一个页面有几个ListBox,它们使用AutoPostBack基于所选值进行一些级联过滤.表单采用所有选定的值,并通过跨页面发布到不同的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" />

如何从ListBoxes的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;"

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读