Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/321.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# ASP.Net CascadingDropDown和EnableEventValidation=";假;_C#_Asp.net_Eventvalidation - Fatal编程技术网

C# ASP.Net CascadingDropDown和EnableEventValidation=";假;

C# ASP.Net CascadingDropDown和EnableEventValidation=";假;,c#,asp.net,eventvalidation,C#,Asp.net,Eventvalidation,我刚刚从AJAX工具包中获得了一个CascadingDropDown,它使用SelectedIndexChanged重定向到一个传递所选值的querystring的页面。我很高兴 但是,我只通过向页面添加EnableEventValidation=“false”使SelectedIndexChanged事件起作用。问题是CascadingDropDown将作为产品选择器放在我网站的主页上 我不想在我的主页上添加EnableEventValidation=“false”!我已经看过MSDN上的Cl

我刚刚从AJAX工具包中获得了一个CascadingDropDown,它使用SelectedIndexChanged重定向到一个传递所选值的querystring的页面。我很高兴

但是,我只通过向页面添加EnableEventValidation=“false”使SelectedIndexChanged事件起作用。问题是CascadingDropDown将作为产品选择器放在我网站的主页上

我不想在我的主页上添加EnableEventValidation=“false”!我已经看过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>

这个令人头痛的问题的答案是自定义下拉控件

因此,为了结束这个问题,并希望帮助其他人绕过这个问题,我做了如下工作:

我用以下代码创建了一个名为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页面(在我的情况下是母版页)上,我放置了以下内容:

<%@ 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>

谢谢你,约翰


希望这有帮助……

您在下拉列表中有什么文本?给我举几个例子。第一个ddl有爱普生打印机的系列名称,即:触笔、触笔颜色、触笔照片。第二个ddl具有相应的型号:BX535WD、DX4000、DX7400 etx。共有8个系列和229台打印机。”“手写笔颜色”是最长的。使用EnableEventValidation=“true”我得到以下JScript运行时错误:Sys.WebForms.PageRequestManagerServerErrorException:回发或回调参数无效。在配置或页面中使用启用事件验证。出于安全目的,此功能验证回发或回调事件的参数是否源自最初呈现它们的服务器控件。如果数据。。。废话废话!@Hari I还应该指出,select值是整数-printerIDs@ComfortablyNumb-您是否尝试过在轻量级更新面板中使用常规下拉列表?如果您的页面经过优化,那么一些额外的异步回发不会造成任何影响,并且可能会解决问题。当然,如果页面生命周期很昂贵,那么这不是一个好的选择。
<p><asp:DdlNoEventValidation ID="DD1" runat="server" /></p>
<p><asp:DdlNoEventValidation ID="DD2" runat="server" 
   onselectedindexchanged="My_SelectedIndexChanged"
   AutoPostBack="True"
   /></p>