我有一个
asp:FormView
在加载到门户页面的控件(在ascx文件中)上,以及其他一些控件。
我需要向表单中添加验证,但是当我添加任何验证控件时,在加载页面时,生成的javascript中会出现明显的随机错误,并且在需要时不会触发验证。
这就是我得到的代码:
<asp:TextBox ID="FPITextBox4" runat="server" Text='<%# Bind("SomeNumber") %>'></asp:TextBox>
<asp:RangeValidator ID="RangeValidator4" runat="server" ControlToValidate="FPITextBox4" Text="*"
ErrorMessage="The number must be a whole number between 0 and 100,000" Type="Integer"
MaximumValue="100000" MinimumValue="0" ToolTip="Must be between 0 and 100,000"></asp:RangeValidator>
这是加载页面时出现的错误:
Message: Expected ';'
Line: 1159
Char: 60
Code: 0
当我查看生成代码中的第1159行时,它看起来是这样的:
var ctl00_ctl00_main_col2_control_0_widgetcontrolX_3eba4918-7c7d-47aa-a089-
fd0ead0609fe_widgetcontrol_3eba4918-7c7d-47aa-a089-
fd0ead0609fe_FormView1_RangeValidator4 = document.all ?
document.all["ctl00_ctl00_main_col2_control_0_widgetcontrolX_3eba4918-7c7d-47aa-a089-
fd0ead0609fe_widgetcontrol_3eba4918-7c7d-47aa-a089-
fd0ead0609fe_FormView1_RangeValidator4"] :
document.getElementById("ctl00_ctl00_main_col2_control_0_widgetcontrolX_3eba4918-7c7d-
47aa-a089-fd0ead0609fe_widgetcontrol_3eba4918-7c7d-47aa-a089-
fd0ead0609fe_FormView1_RangeValidator4");
上面的代码是:
<script type="text/javascript">
//<![CDATA[
var Page_Validators = new Array(document.getElementById(
"ctl00_ctl00_main_col2_control_0_widgetcontrolX_3eba4918-7c7d
-47aa-a089-fd0ead0609fe_widgetcontrol_3eba4918-7c7d-47aa-a089-
fd0ead0609fe_FormView1_RangeValidator4"));
//]]>
</script>
当控件本身被实例化到测试页上时,同样的代码也会工作。
似乎错误只发生在IE8中。我在firefox 3.6中测试了同一个页面,结果一切正常。
修正
验证似乎正在工作。我有一个
ValidationSummary
控件设置为显示一个消息框,但没有显示该消息框,这使我相信验证没有触发。当我把它改成
ShowSummary="true" ShowMessageBox="false"
出现错误消息,数据未保存。
所以现在的意思是我有一个随机的脚本错误,(目前)看起来不会影响页面的工作。
不过,我还是想删除这个错误,以防它隐藏了其他东西。