We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

DateTimePicker lose date value after postback

Hello,
I have following problem: on a View I have a form with two DateTimePickers to select a time span and some other controls. If I submit the form and there are validation errors, the controller returns to this view, but the DateTimePickers are blank, they don't save the selected date's. Is there any possibility to prevent the DateTimePickers from loosing their date's after postback? Or at least can I somehow manually set the date's in the DateTimePickers?
Greetings
Roman Suska 

5 Replies

SN Sasikala Nagarajan Syncfusion Team November 26, 2014 01:13 PM UTC

Hi Roman Suska,

Thanks for using Syncfusion products,

 

We have analyzed your query. We will let you know that we can achieve your requirement using our existing property “enablePersistance” (which is used to Enables or disables the state maintenance of DateTimePicker) in DateTimePicker control. By setting this value to “true” we can maintain the DateTimePicker value even after the post back the form.

 

Please find the below code snippet,

 

[_cshtml]

@Html.EJ().DateTimePicker("SampleDateTime_1").EnablePersistence(true)

                            @Html.EJ().DateTimePicker("SampleDateTime_2").EnablePersistence(true)

 

For your convenience we have prepared the sample based on this. Please find the sample from below location

Sample

 

Please let us know if you have further queries.

 

Regards,

Sasikala Nagarajan



UN Unknown Syncfusion Team November 26, 2014 02:20 PM UTC

Hi Sasikala Nagarajan,
ok I got it, but I have another question. I have a dropdown list with places, that are available on the selected time span. This dropdown is populated with Ajax. After postback or when the page loads I run the script with $(window).load to populate the dropdown list. The problem is with this line:
var startDateTimeObj = $("#dataRozpoczecia").data("ejDateTimePicker"); 

The jQuery code returns "undefined", so I think the control isn't created yet. How can I get the value set on the DateTimePicker after postback or page loading?

Greetings,

Roman Suska



MM Manikandan Mariappan Syncfusion Team November 27, 2014 01:06 PM UTC

Hi Roman Suska,

Sorry for the inconvenience.

We are unable to reproduce the reported issue. We have prepared the sample based on your requirement “To create object in $(window).load time” for the DateTimePicker control and the sample can be downloaded from the following location.

Sample Location : Sample

In this sample we can get the instance of the “DateTimepicker” and it is showcased with message.

Please check with the given sample. If still you face the problem, please revert us by modifying the sample based on your application along with replication procedure. This would be helpful for us to serve you or please share any screen shot of errors.

Please let us know if you have any concerns

Regards,

M.Manikandan



UN Unknown Syncfusion Team November 28, 2014 09:49 AM UTC

Hi,
it seems to work now, I don't know what I did wrong last time. Thanks for helping me.
Greetings,
Roman Suska


SN Sasikala Nagarajan Syncfusion Team December 2, 2014 04:21 AM UTC

Hi Roman,

Thanks for the update,

Please let us know if you have any further assistance.

Regards,

Sasikala Nagarajan



Loader.
Live Chat Icon For mobile
Up arrow icon