[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 779
  • Last Modified:

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!!
0
muligan
Asked:
muligan
  • 2
  • 2
1 Solution
 
muliganAuthor Commented:
BTW... here is my sample javascript that doesn't run:

function ApplyFutureDate(obj)
{
alert(obj);      
//return true;    
}
0
 
Carl TawnSystems 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:
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

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now