.Net validators broken by client-side script (cloneNode does not copy onchange handler)

G

Guest

I am doing some some HTML manipulation in client-side script (IE5.x and IE6.x browsers only).
Something like..

var tmpHTML = oTable.outerHTML
// do something to the HTML her
oTable.outerHTML = tmpHTML

Before the changes, client-side .Net field validators (RegularExpressionValidator, RangeValidator, etc.) work fine... after the changes, the modified HTML works correctly but the validators stop functioning. Seems that the onchange handler of input elements is set by client-side script in WebUIValidation.js

I tried calling ValidatorOnLoad(); hoping to reset all the page's validators, but that didn't work. I think it's because that function is dependent on Page_Validators which is an array of objects instead of object ID's

The onchange handlers I'm trying to preserve do not show up in innerHTML or outerHTML... so they can't be preserved when making dynamic changes to HTML
I was hoping that calling cloneNode on the table I was working on would capture the event handlers but it also skips those (see sample code that demonstrates this below)

So... to the point..
Onchange event handlers generated by .Net validators are applied to page elements in client-side script
Is there a way to preserve the handlers when making modifications (via client side script) to the HTML of the elements the validators are connected to (via the controltovalidate attribute)

Sidenote
I have a hunch that cloneNode not copying these handlers is why IE's Smart Navigation feature causes problems with more advanced pages... but that's just a guess

Thanks
-Mat
______________________________________________
<html><body><form id=form1><input id='moo' type=text onchange="alert('Onchange was not dynamically replaced')" value='MooCow'></form><script
var tmpObj = document.all['moo']
tmpObj.onchange = new Function ("alert('Changed to ' + document.all['moo'].value); ")
alert("Original Object \r\nValue: " + tmpObj.value + "\r\nOnchange: \r\n" + tmpObj.onchange)

var clonedObj = tmpObj.cloneNode(true)
alert("Cloned Object \r\nValue: " + clonedObj.value + "\r\nOnchange: \r\n" + clonedObj.onchange)
</script></body></html
_______________________________________________________________
 
J

John Saunders

MonkeyBoy said:
I am doing some some HTML manipulation in client-side script (IE5.x and IE6.x browsers only).
Something like...

var tmpHTML = oTable.outerHTML;
// do something to the HTML here
oTable.outerHTML = tmpHTML;

Before the changes, client-side .Net field validators
(RegularExpressionValidator, RangeValidator, etc.) work fine... after the
changes, the modified HTML works correctly but the validators stop
functioning. Seems that the onchange handler of input elements is set by
client-side script in WebUIValidation.js.

Maybe the following article will help:


ASP.NET Validation in Depth
(http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/htm
l/aspplusvalid.asp).
 
G

Guest

That's a very detailed article
Thank you

The client-side validators work by adding functions to the onchange property of the objects they validate
I guess because these are 'dynamically' added, they do not show up in the outerHTML of the objects

I ended up writing a client-side routine that recreates the validators and called it whenever the HTML for objects (text inputs) being validated was changed
 

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,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top