GetCallbackEventReference is firing Validators - How to Disable it
We have a server control that inherit from CompositeControl and implements 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.
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).
I've also tried to implement IButtonControl so i can have a CausesValidation property and set it to false, but it didn't work.
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. 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
精彩评论