Avatar of muligan
muliganFlag for United States of America

asked on 

ASP.NET Checkbox onclick with javascript

Hi All,

I'm really scratching my head on why this isn't working.  

Here is my checkbox:
<asp:CheckBox Runat="server" Checked=False id="ApplyFutureDate"></asp:CheckBox>

Here is my code behind:
Protected WithEvents ApplyFutureDate As New System.Web.UI.WebControls.CheckBox

-PageLoad
ApplyFutureDate.Attributes.Add("onClick", "javascript:ApplyFutureDate(this)")

For some reason why I run this, I get a javascript error saying: Object doesn't support this property of method

I even tried OnCheckedChanged and that didnt' work either.

Thoughts?

Thanks!!
ASP.NET

Avatar of undefined
Last Comment
Carl Tawn
Avatar of muligan
muligan
Flag of United States of America image

ASKER

BTW... here is my sample javascript that doesn't run:

function ApplyFutureDate(obj)
{
alert(obj);      
//return true;    
}
ASKER CERTIFIED SOLUTION
Avatar of Carl Tawn
Carl Tawn
Flag of United Kingdom of Great Britain and Northern Ireland image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of muligan
muligan
Flag of United States of America image

ASKER

Wow...how could it be that easy?  For learned purposes... why would the same name cause a conflict?
Avatar of Carl Tawn
Carl Tawn
Flag of United Kingdom of Great Britain and Northern Ireland image

Because ApplyFutureDate has two meanings on the one hand it is a function and on the other it is a checkbox control. When searching for a match the code will bubble, that is it will bubble up the document structure until it finds a match. In your case, the first match it found for ApplyFutureDate was the control, so it tried to execute ApplyFutureDate(this) against the control, which, of course, doesn't have any methods that accpet an object.
ASP.NET
ASP.NET

The successor to Active Server Pages, ASP.NET websites utilize the .NET framework to produce dynamic, data and content-driven web applications and services. ASP.NET code can be written using any .NET supported language. As of 2009, ASP.NET can also apply the Model-View-Controller (MVC) pattern to web applications

128K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo