简体   繁体   English

GetCallbackEventReference正在触发验证器-如何禁用它

[英]GetCallbackEventReference is firing Validators - How to Disable it

We have a server control that inherit from CompositeControl and implements IPostBackDataHandler, ICallbackEventHandler. 我们有一个从CompositeControl继承并实现IPostBackDataHandler,ICallbackEventHandler的服务器控件。

When we fire the CallBackEvent for the control (using Page.ClientScript.GetCallbackEventReference(this, "args", "callBack", "context",true)), in an async mode, it executes the validators of the page that doesn't have a ValidationGroup defined. 当我们为控件触发CallBackEvent时(使用Page.ClientScript.GetCallbackEventReference(this,“ args”,“ callBack”,“ context”,true)),在异步模式下,它将执行不验证页面的验证器具有定义的ValidationGroup。

I need to avoid this behavior without having to set a ValidationGroup to every validator in the page, and i'm tring to not do it with the javascript (i know i could disabled the validators previous the callbackevent, but i'm tring not to get there). 我需要避免这种行为,而不必在页面中的每个验证器上设置ValidationGroup,并且我试图不使用javascript来做到这一点(我知道我可以在回调事件之前禁用验证器,但是我不想这样做。到达那里)。

I've also tried to implement IButtonControl so i can have a CausesValidation property and set it to false, but it didn't work. 我也尝试实现IButtonControl,以便我可以拥有CausesValidation属性并将其设置为false,但是它不起作用。

Does any one have an idea about this issue? 是否有人对此问题有想法?

Thank you in advance!! 先感谢您!!

Sebastián. 塞巴斯蒂安。

I've found a workaround in server code to disable the validators without affecting the page behavior. 我在服务器代码中找到了一种解决方法,可以在不影响页面行为的情况下禁用验证器。

In the LoadPostData event of the control i disable every validator of the page if the callback comes from the control. 在控件的LoadPostData事件中,如果回调来自控件,则禁用页面的每个验证器。 And i've realize that it doesn't affect the behavior, since the real status (the enable property) of the validator doesn't get modified. 而且我意识到它不会影响行为,因为验证器的真实状态(启用属性)不会被修改。 What i mean is: if i make a callback, where i disabled every validator so they don't get fired, and then i make a postback the validators still work properly (if they where enabled before the previous callback) 我的意思是:如果我进行回调,则我禁用了每个验证程序,以免被解雇,然后我进行回发,验证程序仍然可以正常工作(如果在上一个回调之前启用了验证程序)

The Code i've used is: 我使用的代码是:

public virtual bool LoadPostData(string postDataKey, System.Collections.Specialized.NameValueCollection postCollection)
    {
        if (postCollection["__CALLBACKID"] == this.UniqueID)
            foreach (IValidator validator in Page.Validators)
                    (validator as WebControl).Enabled = false;
    }

I use "_ CALLBACKID" to verify the source of the callback, cause "postCollection[" _EVENTTARGET"]" is null since we are in a callback and not in a postback 我使用“ _ CALLBACKID”来验证回调的来源,因为“ postCollection [“ _EVENTTARGET”]“为空,因为我们在回调中,而不在回发中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM