473,327 Members | 2,065 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

Dot Net or Javascript problem???

I have a problem and I'm not sure whether it's Dot Net or Javascript so I'm
posting here.

I have a web page with a text field and a custom validator. The validator
points to a javascript function. The idea is to prevent saving of entries
that are less than 6 characters. The function works fine as long as there is
at least 1 character in the field. What I cannot understand is why it does
not fire at all if the textbox is blank. Here's the code. I put in an alert
to check if it was being called. (Perhaps I should mention that I am an
absolute beginner in Javascript.)

function ValidateLicense(sender,args)
{
var r = document.getElementById("<%= driversLicense.ClientID %>");
args.IsValid = true;
// window.alert(r.value.length);
if (r.value.length < 6)
{
args.IsValid = false;
}
}
Jan 13 '06 #1
3 1104
Those don't fire on blank fields. You have to use a requiredfieldvalidator
in conjunction with your custom one.

The technical reason I am guesing is that the function is hooked up to fire
on the lose focus event, which wouldn't fire if the user never set focus to
the text box in the first place.

"B. Chernick" <BC*******@discussions.microsoft.com> wrote in message
news:3F**********************************@microsof t.com...
I have a problem and I'm not sure whether it's Dot Net or Javascript so I'm
posting here.

I have a web page with a text field and a custom validator. The validator
points to a javascript function. The idea is to prevent saving of entries
that are less than 6 characters. The function works fine as long as there
is
at least 1 character in the field. What I cannot understand is why it
does
not fire at all if the textbox is blank. Here's the code. I put in an
alert
to check if it was being called. (Perhaps I should mention that I am an
absolute beginner in Javascript.)

function ValidateLicense(sender,args)
{
var r = document.getElementById("<%= driversLicense.ClientID %>");
args.IsValid = true;
// window.alert(r.value.length);
if (r.value.length < 6)
{
args.IsValid = false;
}
}

Jan 13 '06 #2
Allow me to refine Marina's answer.

You can omit the control ID assigned to the ControlToValidate property. The
CustomValidator will not know the textbox is blank and will always run.
However, it will not fire during the onchange event.

I put together an article on various problems users face with validators:
http://aspalliance.com/699.

--- Peter Blum
www.PeterBlum.com
Email: PL****@PeterBlum.com
Creator of "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx

"B. Chernick" <BC*******@discussions.microsoft.com> wrote in message
news:3F**********************************@microsof t.com...
I have a problem and I'm not sure whether it's Dot Net or Javascript so I'm
posting here.

I have a web page with a text field and a custom validator. The validator
points to a javascript function. The idea is to prevent saving of entries
that are less than 6 characters. The function works fine as long as there
is
at least 1 character in the field. What I cannot understand is why it
does
not fire at all if the textbox is blank. Here's the code. I put in an
alert
to check if it was being called. (Perhaps I should mention that I am an
absolute beginner in Javascript.)

function ValidateLicense(sender,args)
{
var r = document.getElementById("<%= driversLicense.ClientID %>");
args.IsValid = true;
// window.alert(r.value.length);
if (r.value.length < 6)
{
args.IsValid = false;
}
}

Jan 13 '06 #3
Thanks! (I clearly have some studying to do...)

"Peter Blum" wrote:
Allow me to refine Marina's answer.

You can omit the control ID assigned to the ControlToValidate property. The
CustomValidator will not know the textbox is blank and will always run.
However, it will not fire during the onchange event.

I put together an article on various problems users face with validators:
http://aspalliance.com/699.

--- Peter Blum
www.PeterBlum.com
Email: PL****@PeterBlum.com
Creator of "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx

"B. Chernick" <BC*******@discussions.microsoft.com> wrote in message
news:3F**********************************@microsof t.com...
I have a problem and I'm not sure whether it's Dot Net or Javascript so I'm
posting here.

I have a web page with a text field and a custom validator. The validator
points to a javascript function. The idea is to prevent saving of entries
that are less than 6 characters. The function works fine as long as there
is
at least 1 character in the field. What I cannot understand is why it
does
not fire at all if the textbox is blank. Here's the code. I put in an
alert
to check if it was being called. (Perhaps I should mention that I am an
absolute beginner in Javascript.)

function ValidateLicense(sender,args)
{
var r = document.getElementById("<%= driversLicense.ClientID %>");
args.IsValid = true;
// window.alert(r.value.length);
if (r.value.length < 6)
{
args.IsValid = false;
}
}


Jan 14 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: Kai Grossjohann | last post by:
It seems that Ctrl-N in Mozilla opens a new empty browser window. That's fine, I don't need to do anything about it. But Ctrl-N in IE appears to clone the current window. Is there a way to...
53
by: Cardman | last post by:
Greetings, I am trying to solve a problem that has been inflicting my self created Order Forms for a long time, where the problem is that as I cannot reproduce this error myself, then it is...
6
by: Alex Rast | last post by:
First of all, this is not a programming question. I'm a user, not programming in JavaScript. I'm not, however, a novice user or even a power user - I certainly know programming intimately as well...
136
by: Matt Kruse | last post by:
http://www.JavascriptToolbox.com/bestpractices/ I started writing this up as a guide for some people who were looking for general tips on how to do things the 'right way' with Javascript. Their...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.