0

I have a calender script in my project. For using it, I have added an image and on its onclick event I call a javascript function displayDatePicker:

<img alt="Calender" src="calender.jpg" onclick="displayDatePicker('txtBox1', this);"/>

I use a masterpage in my project and if the image and the associated textbox control are in contentPlaceHolder, the javasript library's function document.getElementsByName returns null and it seems that it can not detect controls inside a contentPlaceHolder.

I used this code for a page that was not using a masterpage and everything went well.

I appreciate any help from you in advance.

Good luck.

ali nasri
  • 19
  • 4
  • this is because the client id are different after rendering. http://stackoverflow.com/questions/1362338/how-do-i-pass-a-server-controls-actual-client-id-to-a-javascript-functioniew – Ratna Aug 13 '13 at 08:19

1 Answers1

0

Your asp textbox may render as something like:

<input name="ctl00$FeaturedContent$txtBox1" id="FeaturedContent_txtBox1" type="text"/>

So, in javascript, you should use clientid:

<img alt="Calender" src="calender.jpg" onclick="displayDatePicker('<%= txtBox1.ClientID %>', this);"/>
afzalulh
  • 7,925
  • 2
  • 26
  • 37