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;
}
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;
}