L
Lewis Holmes
Hi
I have developed a custom server control that basically renders one or more
drop down lists (select html controls) to display a hierarchical lookup
list. So for example you may have lookup data structure that is made up of
3 levels and each level is displayed as a seperate drop down on my web form.
If the user changes the selected value for one of the drop downs, some
javascript executes which dynamically populates the data for the next level
of the hierarchy. This JavaScript is added to the onChange event of the html
select control (drop down).
So for example you may have 3 levels defined as "Car Manufacturer", "Model"
and "Trim". After selecting a car manufacturer, the models available for
that selected manufacturer are then loaded into the Model drop down using
JavaScript.
This all works nicely but then when I add a Compare validator to my web form
dynamically and set it to validate this custom server control, it appears as
if my onChange JavaScript event handler script is being removed. I have been
using IE Developer Toolbar to inspect the DOM and when I dynamically add the
validator, the onChange I already have is being removed. I am 99% sure it is
the presence of the validation control that is removing my onChange
JavaScript.
I decided to have a look into the ASP.NET validation JavaScript and I can
see there is a function that hooks into the onchange events for controls to
make sure the validation script runs when a values is changed. I think this
is the JavaScript that is removing my onChange script.
function ValidatorHookupEvent(control, eventType, functionPrefix) {
var ev;
eval("ev = control." + eventType + ";");
if (typeof(ev) == "function") {
ev = ev.toString();
ev = ev.substring(ev.indexOf("{") + 1, ev.lastIndexOf("}"));
}
else {
ev = "";
}
var func;
if (navigator.appName.toLowerCase().indexOf('explorer') > -1) {
func = new Function(functionPrefix + " " + ev);
}
else {
func = new Function("event", functionPrefix + " " + ev);
}
eval("control." + eventType + " = func;");
}
Please could somebody provide me with some help with this. I am not sure why
my onChange script is being removed and cannot figure out how I can work
around this.
I have developed a custom server control that basically renders one or more
drop down lists (select html controls) to display a hierarchical lookup
list. So for example you may have lookup data structure that is made up of
3 levels and each level is displayed as a seperate drop down on my web form.
If the user changes the selected value for one of the drop downs, some
javascript executes which dynamically populates the data for the next level
of the hierarchy. This JavaScript is added to the onChange event of the html
select control (drop down).
So for example you may have 3 levels defined as "Car Manufacturer", "Model"
and "Trim". After selecting a car manufacturer, the models available for
that selected manufacturer are then loaded into the Model drop down using
JavaScript.
This all works nicely but then when I add a Compare validator to my web form
dynamically and set it to validate this custom server control, it appears as
if my onChange JavaScript event handler script is being removed. I have been
using IE Developer Toolbar to inspect the DOM and when I dynamically add the
validator, the onChange I already have is being removed. I am 99% sure it is
the presence of the validation control that is removing my onChange
JavaScript.
I decided to have a look into the ASP.NET validation JavaScript and I can
see there is a function that hooks into the onchange events for controls to
make sure the validation script runs when a values is changed. I think this
is the JavaScript that is removing my onChange script.
function ValidatorHookupEvent(control, eventType, functionPrefix) {
var ev;
eval("ev = control." + eventType + ";");
if (typeof(ev) == "function") {
ev = ev.toString();
ev = ev.substring(ev.indexOf("{") + 1, ev.lastIndexOf("}"));
}
else {
ev = "";
}
var func;
if (navigator.appName.toLowerCase().indexOf('explorer') > -1) {
func = new Function(functionPrefix + " " + ev);
}
else {
func = new Function("event", functionPrefix + " " + ev);
}
eval("control." + eventType + " = func;");
}
Please could somebody provide me with some help with this. I am not sure why
my onChange script is being removed and cannot figure out how I can work
around this.