views:

77

answers:

5
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
 <link type="text/css" href="App_Themes/jquery-ui-1.7.3.custom.css" rel="stylesheet" />
        <script src="Scripts/jquery-1.3.2.min.js"type="text/javascript"></script>
        <script src="Scripts/jquery-ui-1.7.3.custom.min.js" type="text/javascript"></script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>

    <script type="text/javascript" >
       $("#myButton").click(function() {
          $("#datepicker").datepicker("show");
       });
    </script>
    <form id="form1" runat="server">
    <div>
    <table border="1px" >
     <tr>
        <td><asp:Label ID="Label4" runat="server" Text="Text"></asp:Label></td>
        <td><asp:TextBox ID="TextBox2" runat="server" ></asp:TextBox></td>
    </tr>

    <tr>
        <td><asp:Label ID="Label1" runat="server" Text="Date"></asp:Label></td>
        <td><asp:TextBox ID="datepicker" runat="server"></asp:TextBox>
            <input id="myButton" type="button" value="button" />
        </td>
    </tr></table> 
    </div>
    </form>
</body>
</html>

this is my webform design code..

click function wat written in side script tag is not working...!! Anything wrong.??

A: 

Look at the source code that has been generated. Is the id still called myButton and datepicker ? Often the id's are rewritten by asp.net unless specified otherwise and you are using version 4.

James Westgate
no its written properly.>>
pvaju896
input element is not der,, ? is dat ok.?
pvaju896
A: 

You will need to use the client id of the controls, e.g

$("#<%=datepicker.ClientId%>").datepicker("show");

ca8msm
reformat your code :)
Andreas Niedermair
wrong solution...
Andreas Niedermair
+2  A: 

Add your script to the document.ready(...) function.

One reason it is not working is that when your script is executed, the myButton element has not yet been added to the DOM, and is thus not found. When using jquery, you should generally wrap your javascript code in the $(document).ready(..) to be sure the DOM is fully loaded when your code is invoked. Try the following:

<script type="text/javascript" >
  $(document).ready(function(){
      $("#myButton").click(function() {
          $("#datepicker").datepicker("show");
      });
  });
</script>
Chadwick
so shuould i give the script code snippet below those element TAGS..?/?
pvaju896
wrong reason...
Andreas Niedermair
@Andreas actually it is a partial reason - his click event will not be registered if the element is not in the DOM. It appears there was more to it, but this answer is not wrong information.
Chadwick
that's why it does not state `wrong solution`, but wrong reason. i explicitly took care of your `the reason is...`, which is wrong - it would be the reason if the init happened...
Andreas Niedermair
@pvaju896 You can put a `$(document).ready(...)` before _or_ after the elements in question, since you are registering your function to execute later (when the DOM is ready).
Chadwick
@Andreas corrected the wording `s/The/One/` to be clear that this is not the only fault in the original.
Chadwick
:) - -1, +1 for the dom :)
Andreas Niedermair
+1  A: 

from the documentation:

show

Signature: .datepicker( "show" )

Call up a previously attached date picker.

so first of all you need to attach it!! eg:

$(document).ready(function() {
    var textBox = $('#<%= this.datepicker.ClientID %>');
    var icon = $('#myButton');
    var datepicker = textBox.datepicker();
    icon.click(function() {
        datepicker.datepicker('show');
    });
});

your you might go with the icon-trigger

Andreas Niedermair
var textBox = $('#<%= this.datepicker.ClientID %>');wat's this for..??
pvaju896
its working now the problem was - with initially i dint attach textbox with datepicker..
pvaju896
the `<%= %>` is for retrieving the actual rewritten id of the control
Andreas Niedermair
that's exactly what i've said: you are missing the init!
Andreas Niedermair
actually this is to check..in my project its using master pages..
pvaju896
haha lol!.. I did not noticed your answer is almost the same as mine... +1
Reigel
BC30451: Name 'this' is not declared. am getting one error like this.. wats the 'this' keyword gives..??
pvaju896
`this` is for c#. if you are working with vb.net you might try `Me`
Andreas Niedermair
otherwise just the leave the `this`/`Me` out
Andreas Niedermair
@downvoter: any reason for the downvote?
Andreas Niedermair
+3  A: 

.datepicker( "show" ) -->> Call up a previously attached date picker. but I can't see where you initialize your date picker.. call it like this first... $("#datepicker").datepicker();

$(function() {
    $("#datepicker").datepicker();

    $("#myButton").click(function() {
       $("#datepicker").datepicker("show");
    });
});

try to uncomment this line ($("#datepicker").datepicker();) on the demo

demo

Reigel