0

I have a created a jquery component over asp.net web forms, Its a date picker and in view state I can select my date , but I failed to export my date to my text box. Below is the code of my component I included "date-time-picker.inc"

link rel="stylesheet" type="text/css" href="datetimepicker/jquery.datetimepicker.css"/ >

      <script src="datetimepicker/jquery.datetimepicker.js"></script>
      <input id="datetimepicker1" type="text" />
      <script type="text/javascript">
          jQuery('#datetimepicker1').datetimepicker({
              lang: 'en',
              i18n: {
                  en: {
                      months: [
                     'January', 'February', 'March', 'April',
                     'May', 'June', 'July', 'August',
                     'September', 'October', 'November', 'December',
                         ],
                      dayOfWeek: [
                      "Su.", "Mo", "Tu", "We",
                      "Th", "Fr", "Sa.",
                        ]

                        }
                          },
              timepicker: false,
              format: 'd-m-Y',
              maxDate: '-1970/01/01',
              defaultDate:'true',
              defaultSelect:'true',
              startDate: new Date()

          });

and this is my aspx page looks like

  <label><img src="images1/datetime.jpg" /></label>
            <% 
                Response.WriteFile("components/date-time-picker.inc");
            %>
            <asp:TextBox ID="txtDate" runat="server" ReadOnly = "true"></asp:TextBox>

I tried to put my textbox ID into JQuery("[id$=txtDate]").datetimepicker but then my component get disabled. Can anybody help me which is the best way to export value from jquery into asp.net textbox so I can further process it. Thanks in advance.

2
  • 1
    you have 2 input fields I See, txtDate and datetimepicker1. If you select a date does it get displayed into the datetimepicker1 field? If so why do you want to set it to txtDate? You can make your datetimepicker1 as a ASP.NET TextBox to catch the value in your codebehind. Commented Nov 25, 2014 at 10:20
  • @VDesign Any idea how to do that? Commented Nov 25, 2014 at 20:10

1 Answer 1

1

Your input element as a ASP.NET control:

Change this:

<input id="datetimepicker1" type="text" />

Into this:

<asp:TextBox ID="datetimepicker1" runat="server"></asp:TextBox>

Then your JS code ( selector possible in multiple ways ):

Here I ask to take the input element where the ID ends with $= datetimepicker1 because if you use masterpages there will be a prefix.

    jQuery('input[id$=datetimepicker1]').datetimepicker({
       // code

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

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.