Cancel pagination?

I have a page with several ListBox es that have cascading filtering based on selected values โ€‹โ€‹using AutoPostBack . The form accepts all selected values โ€‹โ€‹and generates an excel doc by inter-page posting to another ASPX. The problem is that after clicking the "Send once" button, it will constantly start postback through the page with every change of choice.

 <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" /> 

How do I undo the reverse crosstab from ListBox es' SelectedIndexChanged events?

Here's the event in code:

 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 
+4
source share
2 answers

This is my current solution using javascript. It works, but it looks like a hack:

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

Edit: adding click event in codebehind:

 ParentItems.Attributes("onclick") = "this.form.action = this.form._initialAction;" 
+1
source

The problem is that using the PostbackUrl property resets the form action to the new URL, and your Ajax calls (or any subsequent reverse copies) use the entire current form action.

Your solution does not work because the submit button is not part of your UpdatePanel, so it never changes.

The easiest solution may be to move the Excel code generating the code from the page on which it is located and to the page you are looking at in the button click handler.

You can probably also include an iframe on the page you're looking at, and send, rather than go to a new page, set the iframe source to the Excel generation page.

Both of these will avoid using PostbackUrl.

0
source

Source: https://habr.com/ru/post/1332526/


All Articles