Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP.NET Validator is removing client onChange event handler for custom server control

Reply
Thread Tools

ASP.NET Validator is removing client onChange event handler for custom server control

 
 
Lewis Holmes
Guest
Posts: n/a
 
      03-10-2009
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.

 
Reply With Quote
 
 
 
 
Allen Chen [MSFT]
Guest
Posts: n/a
 
      03-11-2009
Hi Lewis,

My name is Allen Chen. It's my pleasure to work with you on this issue.

From your description, when CompareValidator is used the JS function hooked
to onchange event doesn't fire, right?

I did a simple test but it worked fine. Here's my test code:

Aspx:

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript">
function Test() {
var d = new Date();
document.getElementById("input1").value = d.getTime();
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
This input is for test. Don't input value in it.
<input id="input1" />
<br />
TextBox1:
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
TextBox2:
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<asp:CompareValidator ControlToValidate="TextBox1"
ControlToCompare="TextBox2" ValueToCompare="Text"
ID="CompareValidator1" runat="server"
ErrorMessage="CompareValidator"></asp:CompareValidator>
<asp:Button ID="Button1" runat="server" Text="Button" />
</div>
</form>
</body>
</html>

Aspx.cs:
protected void Page_Init(object sender, EventArgs e)
{
this.TextBox1.Attributes.Add("onchange", "Test()");
this.TextBox2.Attributes.Add("onchange", "Test()");

}

When you input value into TextBox1 and TextBox2 you can see the Test()
function is always called when the value is changed.

Could you compare your code with mine to see if there's any difference? You
can also send me a demo that can reproduce this problem. My email is
http://www.velocityreviews.com/forums/(E-Mail Removed). Please update here after sending the project in case
I missed that email.

Regards,
Allen Chen
Microsoft Online Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(E-Mail Removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subs...#notifications.

Note: MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 2 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions. Issues of this
nature are best handled working with a dedicated Microsoft Support Engineer
by contacting Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/en-us/subs.../aa948874.aspx
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

 
Reply With Quote
 
 
 
 
Allen Chen [MSFT]
Guest
Posts: n/a
 
      03-13-2009
Hi Lewis,

Do you have any progress on this issue? Have you sent me the project?

Regards,
Allen Chen
Microsoft Online Support

 
Reply With Quote
 
Allen Chen [MSFT]
Guest
Posts: n/a
 
      03-13-2009
Hi Lewis,

Do you have any progress on this issue? Have you sent me the project?

Regards,
Allen Chen
Microsoft Online Support

 
Reply With Quote
 
Lewis Holmes
Guest
Posts: n/a
 
      03-13-2009
Hi Allen

Thanks for your reply. I agree that I ned to reproduce this in a sample
application but that will take some time due to complexity of the code
involved. I will try and strip the code down to the bare minimum needed to
reproduce the issue.

I am aiming to spend sometime to do this next week so I should be able to
send you a sample then. I wish it could be quicker but I have other work
that needs to be completed urgently.

Regards

Lewis

"Allen Chen [MSFT]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi Lewis,
>
> Do you have any progress on this issue? Have you sent me the project?
>
> Regards,
> Allen Chen
> Microsoft Online Support
>


 
Reply With Quote
 
Allen Chen [MSFT]
Guest
Posts: n/a
 
      03-18-2009
Hi Lewis,

Just check back if you've created the demo. Please let me know if you've
done it.

Regards,
Allen Chen
Microsoft Online Support

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Event Handler that creates adds another event handler kaczmar2@gmail.com ASP .Net 1 02-22-2007 07:37 AM
JavaScript error with onChange event handler -- FireFox 1.5 David McNerney Javascript 4 04-06-2006 11:39 PM
Adding custom client-side onClick handler with client-side validator controls Zoe Hart ASP .Net Web Controls 1 01-08-2004 10:45 PM
radio buttons and the onChange event handler Bill Javascript 1 10-23-2003 12:03 AM
Server side validation handler not called for Custom Validator Hunpin Toh ASP .Net Web Controls 0 07-03-2003 04:04 PM



Advertisments