Error in hello world of custom validator :(

S

saurabh

Hey i created a simple page to chk the custom validation control....It
checks if the number is prime or not....I get the following error whn i
run it

A Runtime Error has occured.Do you wish to debug ? line25 error:syntax
error
and whn i debug it i get : Microsoft JScript runtime error: Object
expected

can anybody tell me what could be the error...Here is my small piece of
code...

<%@ Control Language="c#" AutoEventWireup="false"
Codebehind="javacheck.ascx.cs" Inherits="javacheck.javacheck"
TargetSchema="http://schemas.microsoft.com/intellisense/ie5"%>
<script language="javascript">
<!--
function CheckPrime(sender, args)
{
var iPrime = parseInt(args.Value);
var iSqrt = parseInt(Math.sqrt(iPrime));

for (var iLoop=2; iLoop&lt;=iSqrt; iLoop++)
if (iPrime % iLoop == 0)
{
args.IsValid = false;
return;
}

args.IsValid = true;

//-->
</script>
<P>
Trying to learn JavaScript</P>
<P>
<asp:TextBox id="TextBox1" runat="server"></asp:TextBox>&nbsp;
<asp:CustomValidator id="CustomValidator1" runat="server"
ErrorMessage="CustomValidator" ControlToValidate="TextBox1"
ClientValidationFunction="CheckPrime">Number is not
prime</asp:CustomValidator></P>
<P>
<asp:Button id="Button1" runat="server" Text="Button"></asp:Button>
<asp:Label id="Label1" runat="server">Label</asp:Label></P>
 
S

saurabh

saurabh said:
Hey i created a simple page to chk the custom validation control....It
checks if the number is prime or not....I get the following error whn i
run it

A Runtime Error has occured.Do you wish to debug ? line25 error:syntax
error
and whn i debug it i get : Microsoft JScript runtime error: Object
expected

can anybody tell me what could be the error...Here is my small piece of
code...

<%@ Control Language="c#" AutoEventWireup="false"
Codebehind="javacheck.ascx.cs" Inherits="javacheck.javacheck"
TargetSchema="http://schemas.microsoft.com/intellisense/ie5"%>
<script language="javascript">
<!--
function CheckPrime(sender, args)
{
var iPrime = parseInt(args.Value);
var iSqrt = parseInt(Math.sqrt(iPrime));

for (var iLoop=2; iLoop&lt;=iSqrt; iLoop++)
if (iPrime % iLoop == 0)
{
args.IsValid = false;
return;
}

args.IsValid = true;

//-->
</script>
<P>
Trying to learn JavaScript</P>
<P>
<asp:TextBox id="TextBox1" runat="server"></asp:TextBox>&nbsp;
<asp:CustomValidator id="CustomValidator1" runat="server"
ErrorMessage="CustomValidator" ControlToValidate="TextBox1"
ClientValidationFunction="CheckPrime">Number is not
prime</asp:CustomValidator></P>
<P>
<asp:Button id="Button1" runat="server" Text="Button"></asp:Button>
<asp:Label id="Label1" runat="server">Label</asp:Label></P>


hey pls gimme the reply if anybody has any idea...its kindaa urgent and
i seem to be stuck jst because of some silly mistake
 
C

cannontrodder

Saurabh, just a little advise first. Please avoid text/msn speak
("chk","whn" etc) in newsgroups. It's poor netiquette but most
importantly, anything that makes your post harder to read works against
you!

I haven't run your function, but I think I know what is wrong:

<!--
function CheckPrime(sender, args)
{
var iPrime = parseInt(args.Value);
var iSqrt = parseInt(Math.sqrt(iPrime));

for (var iLoop=2; iLoop&lt;=iSqrt; iLoop++)
if (iPrime % iLoop == 0)
{
args.IsValid = false;
return;
}

args.IsValid = true;

//-->

1: You are missing a } after the "args.IsValid = true;" line. When the
CheckPrime function is called further down your page, it can't find
your function as you didn't close it properly so it is not defined.

2: In your 'for' loop you have "iLoop&lt;=iSqrt;" which surely should
be "iLoop<=iSqrt;".

Hope this helps!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top