0

i am creating a web-control and i want to use jquery date-picker on this control, i have tried the below things: 1). apply all the required jquery code in web-control(but it does not work for me.) 2). apply all the required jquery code in page where i am calling that web-control(but it does not work for me.)

Please help me,

Actually what is my purpose to do it is: i want to create a generic module for search, to which i will just pass the name of table it would be work automatically, what i have completed up to now is:

1). bind all the columns in a dropdown list now what i want to do is: if the column type is DateTime then it will show a textbox with jquery calendar.

Please help me to resolve this problem, My code is:

<table>
<tr>
    <td>
        <asp:DropDownList ID="drpColumnName" Width="150px" runat="server" AutoPostBack="true"
            OnSelectedIndexChanged="drpColumnName_SelectedIndexChanged">
        </asp:DropDownList>
    </td>
    <td>
        <asp:DropDownList ID="drpOperation" Width="150px" runat="server">
        </asp:DropDownList>
    </td>
    <td>
        <asp:DropDownList ID="drpCondition" Width="150px" runat="server">
            <asp:ListItem Text="Or" Selected="True" Value="0"></asp:ListItem>
            <asp:ListItem Text="And" Value="1"></asp:ListItem>
        </asp:DropDownList>
    </td>
    <td>
        <asp:TextBox ID="txtSearchText" runat="server" Width="150px"></asp:TextBox>
        <asp:TextBox ID="txtDateSearch" CssClass="myClass" runat="server" Width="150px"></asp:TextBox>
    </td>
    <td>
        <asp:Button ID="btnAddConditionToSearch" runat="server" Text="AddToSearch" OnClick="btnAddConditionToSearch_Click" />
    </td>
</tr>
<tr>
    <td colspan="5">
        &nbsp;
    </td>
</tr>
</table>

Page's code is :

  <form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<div>
    <Search:ctrlSearch ID="cntrlSearch" runat="server" />
</div>
</form>

Jquery code is:

     <script type="text/javascript">
$(document).ready(function () {


    var prm = Sys.WebForms.PageRequestManager.getInstance();
    prm.add_initializeRequest(InitializeRequest);
    prm.add_endRequest(EndRequest);
    // Place here the first init of the DatePicker   

    $('.myclass').datepicker();


});

function InitializeRequest(sender, args) { }
function EndRequest(sender, args) {
    // after update occur on UpdatePanel re-init the DatePicker 

    $('.myclass').datepicker();


}

Please help me,

5 Answers 5

2

Locate your date picker by a class selector.This is much easier than trying to locate ids.In case you have your controls sandwiched in an update panel you have two initialize the datepicker twice.Do this

  <script type="text/javascript">
  $(document).ready(function () {


        var prm = Sys.WebForms.PageRequestManager.getInstance();
        prm.add_initializeRequest(InitializeRequest);
        prm.add_endRequest(EndRequest);
        // Place here the first init of the DatePicker   

        $('.myclass').datepicker();


    });

    function InitializeRequest(sender, args) { }
    function EndRequest(sender, args) {
        // after update occur on UpdatePanel re-init the DatePicker 

        $('.myclass').datepicker();


             }
</script>

Markup`

  <asp:TextBox ID="txtDateSearch" CssClass="myClass" runat="server" Width="150px"></asp:TextBox>

See demo files here

Sign up to request clarification or add additional context in comments.

4 Comments

Where are your query scripts located.They should be on the master page.And indicate if you are using update panels.
i have updated the code, now i can view the div in html rendered using firebug but still not able to display the datepicker
Can you please show me the js files you are using.Put this code on the main aspx page.
I have updated my answer with a dropbox of demo files.I can't see why it should not work.
1

Check like this

$("#<%=txtSearchText.ClientID%>").datepicker();

Comments

0

I think your problem will be because asp.net changes the names and the ID's of elements which are nested in Controls & master pages etc.

Open the source of your page, find the control and double check the ID.

Or as an alternative add a css class to the element and look for that instead of the ID with jQuery.

JA

Comments

0

visit this page jquery-ui-datepicker -> It is ui code. Save this code block as a js file. then source it on your aspx page.

<script src="js/jquery.ui.datepicker-tr.js" type="text/javascript"></script> like this.

$(document).ready(function () {

$('#<%=txtBirthday.ClientID%>').datepicker({
                changeMonth: true,
                changeYear: true,
                yearRange: "-100:-17",
                defaultDate: new Date(1980, 01, 01)
            });

});

and here is the sample code.

Comments

0
<asp:Label ID="Label1" runat="server" Text="From"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>

<asp:Label ID="Label2" runat="server" Text="To"></asp:Label>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>

<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css">
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css">
<script>
  $(function() {
    $( "#TextBox1" ).datepicker();
  });
  $(function() {
    $( "#TextBox2" ).datepicker();
  });
</script>

Comments

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.