4

ListBoxを使用して選択した値に基づいてカスケード フィルタリングを行ういくつかの es を持つページがありますAutoPostBack。フォームは、選択されたすべての値を取得し、別の ASPX へのクロスページ投稿によって Excel ドキュメントを生成します。問題は、送信を 1 回クリックした後、選択が変更されるたびにクロスページ ポストバックが継続的に発生することです。

<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
4

2 に答える 2

1

これは、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;"
于 2010-12-17T17:41:43.740 に答える
0

The problem is that using the PostbackUrl property resets the form action to a new URL, and your Ajax calls (or any subsequent postbacks) use whatever the current action of the form is.

Your solution doesn't work because the submit button isn't part of your UpdatePanel, so it never gets modified.

The easiest solution might be to move your Excel file generating code out of the page it's in, and into the page you're looking at, in the click handler of the button.

You also could probably include an iframe on the page you're looking at, and on submit, rather than going to a new page, set the source of the iframe to the Excel-generating page.

Both of these would avoid the need for using the PostbackUrl.

于 2010-12-17T17:27:46.613 に答える