5

Following date picker is not work in asp.net web form. I changed code so many time not even other example are working & even create new page to test still not working.

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="test.aspx.cs" Inherits="test" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.min.js" type = "text/javascript"></script>
    <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js" type = "text/javascript"></script>
    <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel = "Stylesheet" type="text/css" /> 
    <script type="text/javascript">

//Code Starts
$(document).ready(function() {

     $('#Text1').datepicker();
      $('#<%=txtBookDate.ClientID %>').datepicker();
});​

</script>
</head>

<body>
    <form id="form1" runat="server">
    <div>
     <asp:TextBox ID="txtBookDate" runat="server"></asp:TextBox><input id="Text1" type="text" />
    </div>
    </form>
</body>
</html>

Example on jsFiddler is working

http://jsfiddle.net/ANdUK/3/

3
  • Have you tried moving the jQuery script to just below </Body>? Commented May 30, 2012 at 10:37
  • Yes, I even did that but it is still not working similar example for jSfiddler is working http://jsfiddle.net/ANdUK/3/ Commented May 30, 2012 at 10:41
  • Ok, If you replace the .datePicker call with an alert('test'); do you get the alert shown? perhaps document.ready is not getting fired. If the alert does not get fired perhaps its having trouble pulling the scripts from google Commented May 30, 2012 at 10:44

2 Answers 2

1

The problem is probably that the ids are changed somehow because they are inside a form. You should check the generated id and use it. BTW the example on jsfiddle doesn't work without jQuery UI

EDIT try not to put spaces in the script tag and try taking the normal input outside the form

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.min.js" type="text/javascript"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js" type="text/javascript"></script>
Sign up to request clarification or add additional context in comments.

4 Comments

Example is working it was broken. I have test even in the source ID generate is correct for asp.net even. If that is the case then it should atleast work for simple HTML control which it is not
@KnowledgeSeeker have you tried taking off the spaces from the script tag after the type property?Also try to take the normal input outside the form
I have removed space did same thing as you suggested. for some reason it is not working..
@KnowledgeSeeker that's strange, but with the firebug console do you see any error?
0

After the final semi-colon in the following line of code:

$(document).ready(function() {

     $('#Text1').datepicker();
      $('#<%=txtBookDate.ClientID %>').datepicker();
});​

You have some sort of dodgy character. Delete it and you'll be good to go.

2 Comments

I notice ? was generate when i moved same code to notepad and create simple .html from it i removed the invincible character which was like ? in notepad. and then code started to worker. I removed all the code and added script files and controls not it works fine. Thanks everyone.. This is frustrating when you cant see something which is creating unexpected results. Cant believe i wasted 2 hours with this issue
It came up as a javascript error in FireBug when I tried it, which made it easy to find. If you haven't already, I'd recommend you familiarise yourself with FireBug or Chrome Developer Tools. Best wishes, Carl.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.