views:

38

answers:

4

can i use jquery date picker with usercontrol of ASP.Net..?/

i tried but its not working - but i tried with Default.aspx page, its working normal ??

wat should i do to use with Usercontrol.??

A: 

JQuery controls are fully client side. This means that after the server processes the UserControl, adding it into the Default.aspx page, then the client will just see a single html page with the jQuery markup included.

So in short, yes the jQuery will work with userControls as long as the UserControl is added properly into the page.

rockinthesixstring
A: 

Without seeing the code, the best guess I have is that your control's ID isn't correct. Remember that ASP.NET, if you have a server control inside of a user control (or other container-type objects), then the ID that shows up on the page isn't what you put in your markup, but rather a generated unique ID.

So if you're using an <asp:TextBox>, then make sure you're putting the full ID in your javascript, like:

$("#<%= myTextBox.ClientID %>").datepicker();
Joe Enos
ah yes, this is especially true if also using MasterPages.
rockinthesixstring
A: 

Rick Strahl made an ASP.Net control basedon the jQuery date picker. You can grab it here

TheGeekYouNeed
+2  A: 

I would use an external .js file for this, and remove the reliance on IDs or names (which ASP.Net will screw with, in < 4.0 anyway), like this:

In your userControl:

<asp:TextBox ID="anything" CssClass="datepicker" />

In your .js file, use a class selector instead of the ID, like this:

$(".datepicker").datepicker();

Using a class means one set of code for any number of these datepickers in the page and you don't have to worry about what the IDs are going to look like in the page...they just won't be used for this.

Nick Craver
I like it - very straightforward.
Joe Enos
$(".datepicker").datepicker(); this string inside $ symbol means classes rite??/ k- class selector..!!how do i make dat now?? so is that "class" is in javascript or....??
pvaju896
@pvaju896 - It's just a CSS class, in your page that textbox will render (with a few more properties) like this: `<input type="text" class="datepicker" />`, doing `$(".datepicker")` in jQuery will find elements that have this CSS class...it doesn't need to actually have a CSS style to go with it, we're just using it for jQuery to find the element.
Nick Craver