ASP.Net CascadingDropDown和EnableEventValidation ="假" [英] ASP.Net CascadingDropDown and EnableEventValidation="false"

查看:217
本文介绍了ASP.Net CascadingDropDown和EnableEventValidation ="假"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚从Ajax工具包与合作的SelectedIndexChanged重定向到传递所选值的查询字符串一个页面CascadingDropDown。我很好chuffed!

不过,我只得到了SelectedIndexChanged事件加入EnableEventValidation =false的页面工作。问题是CascadingDropDown将被放置在母版我的网站作为产品选择。

我不热衷于加入EnableEventValidation =false以我的母版!我看MSDN上的ClientScriptManager.RegisterForEventValidation方法,它是正确的走在我的头上。

什么是做的最好的事情?是否有使用ClientScriptManager.RegisterForEventValidation一个简单的例子?

干杯...

编辑:这里是code:

 < ASP:的ScriptManager ID =汇编=服务器/>
< D​​IV>
    系列:LT; ASP:DropDownList的ID =SeriesList=服务器/>< BR />
    打印机:< ASP:DropDownList的ID =PrinterList=服务器
                 onselectedindexchanged =PrinterList_SelectedIndexChanged
             的AutoPostBack =真/>< BR />
< / DIV>    < ASP:CascadingDropDown ID =CCD1=服务器
        ServicePath =CascadingDropdown1.cs.asmxServiceMethod =GetSeries
        的TargetControlID =SeriesList类别=系列
        PromptText =SELECT系列/>
    < ASP:CascadingDropDown ID =CCD2=服务器
        ServicePath =CascadingDropdown1.cs.asmxServiceMethod =GetPrintersForSeries
        的TargetControlID =PrinterListParentControlID =SeriesList类别=打印机
        PromptText =选择打印机/>    < ASP:的UpdatePanel ID =UpdatePanel1=服务器>        <&触发器GT;
            < ASP:AsyncPostBackTrigger控件ID =PrinterList事件名称=的SelectedIndexChanged/>
        < /触发器>
    < / ASP:的UpdatePanel>

和这里的事件:

 保护无效PrinterList_SelectedIndexChanged(对象发件人,EventArgs的发送)
        {
            INT printerID = Convert.ToInt32(PrinterList.SelectedValue);
            System.Web.HttpContext.Current.Response.Redirect(Default.aspx的PID =?+ printerID);
        }


解决方案

这个问题的答案颈项强痛问题是定制的下拉控件!

因此​​,要关闭掉这个问题,希望能帮助别人避开这里这个问题是我做过什么:

我创建了一个叫做用下面的code NoValidationDropDownList.cs一个CS文件

 使用系统;
使用System.Collections.Generic;
使用System.Linq的;
使用的System.Web;
使用System.Web.UI.WebControls;命名空间My.Namespace.Controls
{
    公共类DdlNoEventValidation:DropDownList的
    {
    }
}

然后当下拉控件驻留(在我的情况下,母版)aspx页面上我放在这个:

 <%@注册标签preFIX =ASP命名空间=My.Namespace.Controls%GT;

接下来,我修改了级联下拉框,像这样:

 < P>< ASP:DdlNoEventValidation ID =DD1=服务器/>< / P>
< P>< ASP:DdlNoEventValidation ID =DD2=服务器
   onselectedindexchanged =My_SelectedIndexChanged
   的AutoPostBack =真
   />&下; / P>

据我了解,创建自定义下拉控件规避事件验证。这样,你不需要关掉事件验证整个页面。在我的例子作为对照组都坐在母版,事件验证将被关闭整个网站!

唉,这不是我的原创作品所以这里是原来的参考:<一href=\"http://johanleino.word$p$pss.com/2009/11/17/cascadingdropdown-casues-invalid-postback-or-callback-argument-error/\" rel=\"nofollow\">http://johanleino.word$p$pss.com/2009/11/17/cascadingdropdown-casues-invalid-postback-or-callback-argument-error/

感谢约翰!

希望这有助于...

I have just got a CascadingDropDown from the AJAX Toolkit working with SelectedIndexChanged to redirect to a page passing a querystring of the selected value. I'm well chuffed!

However, I only got the SelectedIndexChanged event working by adding EnableEventValidation="false" to the page. The problem is the CascadingDropDown will be placed in the MasterPage of my website as a product selector.

I'm not keen on adding EnableEventValidation="false" to my MasterPage! I've looked at the ClientScriptManager.RegisterForEventValidation method on MSDN and it's gone right over my head.

What's the best thing to do? Is there a simple example of using ClientScriptManager.RegisterForEventValidation?

Cheers...

EDIT: Here's the code:

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

And here's the event:

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

解决方案

The answer to this pain in the neck problem is custom dropdown controls!

So to close off this question and hopefully help someone else get round this issue here is what I did:

I created a cs file called NoValidationDropDownList.cs with the following code

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
    {
    }
}

Then on the aspx page where the dropdown controls reside (in my case a MasterPage) I placed this:

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

Next I amended the cascade dropdown boxes like so:

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

As I understand it, creating a custom dropdown control circumvents event validation. In this way you don't need to switch off event validation for the entire page. In my case as the controls are sitting in the MasterPage, event validation would have been switched off for the entire site!

Alas this is not my original work so here is the original reference: http://johanleino.wordpress.com/2009/11/17/cascadingdropdown-casues-invalid-postback-or-callback-argument-error/

Thanks Johan!

Hope this helps...

这篇关于ASP.Net CascadingDropDown和EnableEventValidation =&QUOT;假&QUOT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆