Odd crash involving Javascript and a calendar control

B

B. Chernick

I'm writing a web app in VB/Asp.net 2.0. I have a screen with a detailsview.
In this detailsview are 2 template fields. The first field contains a
dropdown list, a custom validator, and a hyperlink. The second contains a
pair of calendar controls.

I had what I thought was a neat little hack: The validator for the dropdown
list calls a javascript function that both validates the dropdown (-1 means
nothing selected.) and updates the target of the hyperlink based on the value
of the dropdown list. That part works fine.

The problem is that when I select a date on either calendar, the screen
crashes with the error: "Object reference not set to an instance of an
object." The problem line is the first reference to the hyperlink in the
javascript code. Since the calendars have nothing to do with these other
controls, I'm more than a little confused. Here's the javascript code.
(I've also tried Javascript error trapping but that doesn't seem to work
either. Admittedly I'm a bit out of practice with JS.)

function ValidateEmpDropdown(sender, args)
{
args.IsValid = (new Number(args.Value)) >= 0;
if ((new Number(args.Value)) >=0 )
{
document.getElementById("<%= hlEmp.ClientId %>").href =
"EditEmployee.aspx?EmployeeId=" + (new Number(args.Value));
}
else
{
document.getElementById("<%= hlEmp.ClientId %>").href =
"DisplayEmployees.aspx";
}
return args.IsValid;
}
 
B

B. Chernick

Never mind. Found the problem (or at least a temporary trial and error
solution.) The hyperlink handle was being set in the DetailsView's databound
event. I restored it on postbacks. Now to look at calendar control
alternatives...
 

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

Forum statistics

Threads
473,754
Messages
2,569,527
Members
44,998
Latest member
MarissaEub

Latest Threads

Top