通过ajax调用页面时ASP.Net验证无效

时间:2020-12-30 02:01:32

I have a page "MyPage.aspx" that calls "MyForm.aspx" with prototype

我有一个页面“MyPage.aspx”,用原型调用“MyForm.aspx”

new Ajax.Updater('display', '/myform.aspx' etc....

新的Ajax.Updater('display','/ myform.aspx'等....

However, when the page renders there are no validation scripts on the page.

但是,当页面呈现时,页面上没有验证脚本。

ie, i don't see scripts like below when i call the page via ajax. If just call myForm.aspx i see the below scripts

即,当我通过ajax调用页面时,我没有看到类似下面的脚本。如果只是调用myForm.aspx,我会看到以下脚本

<script type="text/javascript">
//<![CDATA[
var FlagForm1_RequiredFieldValidator1 = document.all ? document.all["FlagForm1_RequiredFieldValidator1"] : document.getElementById("FlagForm1_RequiredFieldValidator1");
FlagForm1_RequiredFieldValidator1.controltovalidate = "FlagForm1_TextBoxName";
FlagForm1_RequiredFieldValidator1.errormessage = "RequiredFieldValidator";
FlagForm1_RequiredFieldValidator1.evaluationfunction = "RequiredFieldValidatorEvaluateIsValid";
FlagForm1_RequiredFieldValidator1.initialvalue = "";
var FlagForm1_RequiredFieldValidator2 = document.all ? document.all["FlagForm1_RequiredFieldValidator2"] : document.getElementById("FlagForm1_RequiredFieldValidator2");
FlagForm1_RequiredFieldValidator2.controltovalidate = "FlagForm1_TextBoxEmail";
FlagForm1_RequiredFieldValidator2.errormessage = "RequiredFieldValidator";
FlagForm1_RequiredFieldValidator2.evaluationfunction = "RequiredFieldValidatorEvaluateIsValid";
FlagForm1_RequiredFieldValidator2.initialvalue = "";
var FlagForm1_RequiredFieldValidator3 = document.all ? document.all["FlagForm1_RequiredFieldValidator3"] : document.getElementById("FlagForm1_RequiredFieldValidator3");
FlagForm1_RequiredFieldValidator3.controltovalidate = "FlagForm1_TextBoxComment";
FlagForm1_RequiredFieldValidator3.errormessage = "RequiredFieldValidator";
FlagForm1_RequiredFieldValidator3.evaluationfunction = "RequiredFieldValidatorEvaluateIsValid";
FlagForm1_RequiredFieldValidator3.initialvalue = "";
//]]>
</script>

1 个解决方案

#1


you need to set evalscripts:true. As the property name suggest this allows the scripts to be evaluated. Also, you need to put the scripts in the parent page.

你需要设置evalscripts:true。正如属性名称所示,这允许对脚本进行评估。此外,您需要将脚本放在父页面中。

   var myAjax = new Ajax.Updater(
                    'container',
                    url,
                    {
                    asynchronous:true,
                    method: 'get',
                    parameters: pars,
                    evalScripts: true,
                    onFailure: reportError
                    }
                 );

#1


you need to set evalscripts:true. As the property name suggest this allows the scripts to be evaluated. Also, you need to put the scripts in the parent page.

你需要设置evalscripts:true。正如属性名称所示,这允许对脚本进行评估。此外,您需要将脚本放在父页面中。

   var myAjax = new Ajax.Updater(
                    'container',
                    url,
                    {
                    asynchronous:true,
                    method: 'get',
                    parameters: pars,
                    evalScripts: true,
                    onFailure: reportError
                    }
                 );