By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,010 Members | 2,774 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,010 IT Pros & Developers. It's quick & easy.

Error in hello world of custom validator :(

P: n/a
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>

Jul 27 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a

saurabh wrote:
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

Jul 27 '06 #2

P: n/a
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!

saurabh wrote:
saurabh wrote:
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
Jul 27 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.