1

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.

4
  • the specified line seems to be ok. Are you using Internet Explorer? IE sometimes gives an incorrect line-number. You could try to debug with Microsofts Script Editor: jonathanboutelle.com/mt/archives/2006/01/howto_debug_jav.html Commented Feb 5, 2010 at 13:21
  • Since the error message indicates that a javascript line isn't terminated, the first thing I would try is removing the commas from 100,000. Commented Feb 5, 2010 at 13:24
  • @Pbirkoff - I am using IE, but if I add & remove other validation elements the line number moves around in line with the added/removed code. I'll try Firefox. Commented Feb 5, 2010 at 13:24
  • @Jamie - Good idea, but removing the comments had no effect. Commented Feb 5, 2010 at 13:25

2 Answers 2

3

you really found a bug in .Net client generation code - have a look at http://haacked.com/archive/2006/07/14/ASP.NET2.0ClientValidationJavascriptBug.aspx

But no resolution from M$ - you'll have to generate IDs in a different way...

Sign up to request clarification or add additional context in comments.

3 Comments

Interesting link. I don't think I've got any control ID's with "."'s in them, but I'll double check.
Just checked, no "."'s but the generated name is 160 characters long. Perhaps that's the issue. More investigation needed.
Yes, you do have one of forbidden characters there: "-". Have a look at Note of Control.ID msdn.microsoft.com/en-us/library/system.web.ui.control.id.aspx Use guid.ToString("n") if that's the only problem. Peter Ivan
0

I've found that this type of error results because of an error in one of my scripts, where there is a missing ;. Do you have JS code in your page and is all of that correct, no missing semi-colons?

HTH.

1 Comment

That was my first thought, but the only change I've made is to add the <asp:RangeValidator .../> into the aspx. I've not added any new JavaScript to the page, which is what's really confusing me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.