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!!
muliganAsked:
Who is Participating?
 
Carl TawnConnect With a Mentor Systems and Integration DeveloperCommented:
I think its a name conflict between your function and the checkbox name. Try changing your javascript function name.
0
 
muliganAuthor Commented:
BTW... here is my sample javascript that doesn't run:

function ApplyFutureDate(obj)
{
alert(obj);      
//return true;    
}
0
 
muliganAuthor Commented:
Wow...how could it be that easy?  For learned purposes... why would the same name cause a conflict?
0
 
Carl TawnSystems and Integration DeveloperCommented:
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.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.