I have an asp:FormView
on a control (in an ascx file) which is loaded onto a portal page along with some other controls.
I need to add validation to the form, but when I add any of the validation controls I get an apparently random error in the generated JavaScript when the page is loaded, and the validation doesn't fire when I need it to.
This is the code that I've got:
<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>
This is the error I get when the page is loaded:
Message: Expected ';'
Line: 1159
Char: 60
Code: 0
When I look at line 1159 in the generated code it looks like this:
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");
The code immediately above this is:
<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>
The same code works when the control is just instantiated onto a test page all by itself.
It appears that the error only happens in IE 8. I've tested the same page in Firefox 3.6 and it all works as expected.
Correction
It appears that the validation is working. I had a ValidationSummary
control set to show a message box and that wasn't appearing which led me to believe that the validation wasn't firing. When I changed that to ShowSummary="true" ShowMessageBox="false"
the error message did appear and the data isn't saved.
So all it means now is that I've got a random script error that (at the moment) doesn't appear to be affecting the workings of the page.
However, I would still like to remove the error - just in case it's hiding something else.