ICallBackEventHandler不会使用表单值更新控件

时间:2022-11-19 15:53:52

I want to use ICallBackEventHandler however when I use it to call back to the server I find that my form control objects don't have the latest form values. Is there a way to force populate the values with the form data?

我想使用ICallBackEventHandler但是当我用它来回调服务器时,我发现我的表单控件对象没有最新的表单值。有没有办法强制使用表单数据填充值?

Thanks.

2 个解决方案

#1


Have a look at http://msdn.microsoft.com/en-us/magazine/cc163863.aspx.

看看http://msdn.microsoft.com/en-us/magazine/cc163863.aspx。

In short, you have to clear the variable '__theFormPostData', and call the 'WebForm_InitCallback()' before the 'CallbackEventReference' script. This updates the form values with the user input values. Something like this:

简而言之,您必须清除变量'__theFormPostData',并在'CallbackEventReference'脚本之前调用'WebForm_InitCallback()'。这将使用用户输入值更新表单值。像这样的东西:

// from the above link
string js = String.Format("javascript:{0};{1};{2}; return false;", 
    "__theFormPostData = ''",
    "WebForm_InitCallback()",
    Page.GetCallbackEventReference(this, args, "CallbackValidator_UpdateUI", "null"));

#2


You obviously still dont have the same issue but wha you need to do is recall WebForm_InitCallback() prior to your JavaScript Callback Code. This will get the page to refresh the POST values in your Request.Form object.

您显然仍然没有相同的问题,但您需要做的是在JavaScript回调代码之前调用WebForm_InitCallback()。这将使页面刷新Request.Form对象中的POST值。

When you now do a PostBack the values modified during Callbacks will be available. It goes without saying they will be available during Callbacks.

当您现在执行PostBack时,将在回调期间修改的值可用。不言而喻,它们将在Callbacks期间可用。

etc

function SomeCode()
{
    __theFormPostCollection.length = 0;
    __theFormPostData = "";
    WebForm_InitCallback();

    ExecuteMyCallbackMethod("yaday", "yadya");
}

#1


Have a look at http://msdn.microsoft.com/en-us/magazine/cc163863.aspx.

看看http://msdn.microsoft.com/en-us/magazine/cc163863.aspx。

In short, you have to clear the variable '__theFormPostData', and call the 'WebForm_InitCallback()' before the 'CallbackEventReference' script. This updates the form values with the user input values. Something like this:

简而言之,您必须清除变量'__theFormPostData',并在'CallbackEventReference'脚本之前调用'WebForm_InitCallback()'。这将使用用户输入值更新表单值。像这样的东西:

// from the above link
string js = String.Format("javascript:{0};{1};{2}; return false;", 
    "__theFormPostData = ''",
    "WebForm_InitCallback()",
    Page.GetCallbackEventReference(this, args, "CallbackValidator_UpdateUI", "null"));

#2


You obviously still dont have the same issue but wha you need to do is recall WebForm_InitCallback() prior to your JavaScript Callback Code. This will get the page to refresh the POST values in your Request.Form object.

您显然仍然没有相同的问题,但您需要做的是在JavaScript回调代码之前调用WebForm_InitCallback()。这将使页面刷新Request.Form对象中的POST值。

When you now do a PostBack the values modified during Callbacks will be available. It goes without saying they will be available during Callbacks.

当您现在执行PostBack时,将在回调期间修改的值可用。不言而喻,它们将在Callbacks期间可用。

etc

function SomeCode()
{
    __theFormPostCollection.length = 0;
    __theFormPostData = "";
    WebForm_InitCallback();

    ExecuteMyCallbackMethod("yaday", "yadya");
}