views:

390

answers:

3

I'm trying to use the jquery datepicker - http://jqueryui.com/demos/datepicker/ in a custom control (.ascx).

To enable the datepicker, I need to add the following script at the top for an input:

$("#dateinput").datepicker({});

The problem is, that the id of the element changes when the custom control is on a page. When the custom control is given an id of "c1" for example, the id field becomes "c1_dateinput".

How do I get around this? I need multiple custom controls with datepickers on the page.

+3  A: 

If you need multiple controls to have datepickers I would use a class. Assign a CSS class to anything that needs a datepicker and your javascript becomes this:

$(".datepicker").datepicker();
Andy Gaskell
A: 

You will need to use the Control.ClientID property to get around this. This way you can get the rendered client id no matter what it is.

Andrew Siemer
+1  A: 

use a class say date.

Then simply do -

$("input.date").datepicker();

This will create a datepicker for each input that has a class of date.

redsquare