我刚刚从 AJAX 工具包中获得了 CascadingDropDown,它使用 SelectedIndexChanged 重定向到传递所选值的查询字符串的页面。我很高兴!
但是,我只是通过将 EnableEventValidation="false" 添加到页面来使 SelectedIndexChanged 事件起作用。问题是 CascadingDropDown 将作为产品选择器放置在我网站的 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);
}