Pass datetimepicker value to codebehind (C #)

I want to pass the datetimepicker value to my Codebehind (C #) and store it in a variable in C #.

I tried it with a hidden field, but it does not work.

here is the js code:

var dates = $("#ArrivalStartDatepicker").datetimepicker({
                            defaultDate: "+lw",
                            dateFormat: 'dd-mm-yy',
                            changeMonth: true,
                            numberOfMonths: 2,
                            ampm: true,
                            stepMinute: 10,
                            minuteGrid: 10,
                            onSelect: function (selectedDate) {
                                    document.getElementById("ArrivalStart").value = dates.datetimepicker('getDate');
                                }
                            });

hidden field:

<div>
          <input type="hidden" id="ArrivalStart" runat="server"/> 
</div>

when I select a date or time, firebug raises the following error:

document.getElementById ("ArrivalStart") is null

this tells me that ArrivalStart-Field is not available in JS.

How can I manage this?

Greetz

Tobi

+3
source share
2 answers

Instead

 document.getElementById("ArrivalStart")

using

  document.getElementById("<%= ArrivalStart.ClientId %>")

This way you enter the identifier generated by ASP.Net.


javascript aspx ( js), ASP.Net <%= .. %> ArrivalStart.

+4

runat = server, # . , , , - .

" ", - "ArrivalStart" ?

If this is not the case, you can use C # to write the ClientID of the control (Control.ClientID) to your jQuery script

I could bark the wrong tree though :)

+1
source

All Articles