3

SelectedIndexChanged を使用して AJAX Toolkit から CascadingDropDown を取得し、選択した値のクエリ文字列を渡すページにリダイレクトしました。元気いっぱいです!

ただし、ページに EnableEventValidation="false" を追加することによってのみ SelectedIndexChanged イベントが機能しました。問題は、CascadingDropDown が私の Web サイトの MasterPage に製品セレクターとして配置されることです。

EnableEventValidation="false" を MasterPage に追加したくありません。MSDN で ClientScriptManager.RegisterForEventValidation メソッドを見てきましたが、頭から離れません。

どうするのが一番いいですか?ClientScriptManager.RegisterForEventValidation を使用する簡単な例はありますか?

乾杯...

編集: コードは次のとおりです。

<asp:ScriptManager ID="asm" runat="server" />
<div>
    Series:     <asp:DropDownList ID="SeriesList" runat="server" /><br />
    Printers:   <asp:DropDownList ID="PrinterList" runat="server" 
                 onselectedindexchanged="PrinterList_SelectedIndexChanged"
             AutoPostBack="True" /><br />
</div>

    <asp:CascadingDropDown ID="ccd1" runat="server"
        ServicePath="CascadingDropdown1.cs.asmx" ServiceMethod="GetSeries" 
        TargetControlID="SeriesList" Category="Series"
        PromptText="Select Series" />
    <asp:CascadingDropDown ID="ccd2" runat="server"
        ServicePath="CascadingDropdown1.cs.asmx" ServiceMethod="GetPrintersForSeries"
        TargetControlID="PrinterList" ParentControlID="SeriesList" Category="Printer" 
        PromptText="Select Printer" />

    <asp:UpdatePanel ID="UpdatePanel1" runat="server">

        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="PrinterList" EventName="SelectedIndexChanged" />
        </Triggers>
    </asp:UpdatePanel>

そして、イベントは次のとおりです。

protected void PrinterList_SelectedIndexChanged(object sender, EventArgs e)
        {
            int printerID = Convert.ToInt32(PrinterList.SelectedValue);
            System.Web.HttpContext.Current.Response.Redirect("Default.aspx?PID="+printerID);
        }
4

1 に答える 1

2

この首の問題に対する答えは、カスタム ドロップダウン コントロールです。

したがって、この質問を締めくくり、できれば他の誰かがこの問題を回避するのを助けるために、ここで私がしたことは次のとおりです。

次のコードで NoValidationDropDownList.cs という名前の cs ファイルを作成しました

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI.WebControls;

namespace My.Namespace.Controls
{
    public class DdlNoEventValidation : DropDownList
    {
    }
}

次に、ドロップダウン コントロールが存在する aspx ページ (私の場合は MasterPage) に、次のように配置しました。

<%@ Register TagPrefix="asp" Namespace="My.Namespace.Controls" %>

次に、カスケード ドロップダウン ボックスを次のように修正しました。

<p><asp:DdlNoEventValidation ID="DD1" runat="server" /></p>
<p><asp:DdlNoEventValidation ID="DD2" runat="server" 
   onselectedindexchanged="My_SelectedIndexChanged"
   AutoPostBack="True"
   /></p>

私が理解しているように、カスタム ドロップダウン コントロールを作成すると、イベントの検証が回避されます。この方法では、ページ全体のイベント検証をオフにする必要はありません。私の場合、コントロールは MasterPage にあるため、イベントの検証はサイト全体でオフになっています。

悲しいかな、これは私のオリジナルの作品ではないので、元の参照は次のとおりです

ありがとうヨハン!

お役に立てれば...

于 2012-02-21T12:34:56.190 に答える