By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,606 Members | 2,016 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,606 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
__________________________________________________ _____________

Jul 21 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
"MonkeyBoy" <an*******@discussions.microsoft.com> wrote in message
news:02**********************************@microsof t.com...
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/de...-us/dnaspp/htm
l/aspplusvalid.asp).
--
John Saunders
johnwsaundersiii at hotmail

Jul 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.