Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET textbox with jQuery UI DatePicker value lost when doing a postback

I've got an application that uses jQuery UI DatePicker on an ASP.NET textbox control.

The control is working as intended, but I've noticed that when you postback from a server call (via submit button), the entered value gets lost in the application.

Was wondering if you all have experienced this? What measures that you have to do to prevent this?

<asp:TextBox runat="server" ID="txtCallsMadeFrom" class="field" EnableViewState="true">

var callsMadeFromId = '#<%=txtCallsMadeFrom.ClientID %>';
jQuery(callsMadeFromId).datepicker({ showOn: "button", buttonImage: "../images/calendar.gif", altFormat: 'dd/mm/yy', buttonImageOnly: true, onSelect: function () { } });
like image 720
mallows98 Avatar asked Mar 10 '11 04:03

mallows98


3 Answers

I faced this issue as well and even after trying to set view state on page or for control it did not workout. The approach to use a hidden field required to me manage sync between date field and the hidden field as the user was playing with the dates. So I decided to set the date again on document.ready as given in the post here, hope this helps.

http://www.himanshusaxena.net/asp-net-text-box-with-jquery-ui-date-picker-value-lost-on-a-post-back/

like image 102
Himanshu Kumar Avatar answered Oct 07 '22 14:10

Himanshu Kumar


You could consider saving the Textbox's value in a hidden field. I do that with Jquery tabcontrols as they also forget which tab is selected during a postback.

like image 34
Johnny DropTables Avatar answered Oct 07 '22 14:10

Johnny DropTables


Make sure that you haven't put <%@ Page EnableViewState="false"%> in .. if you have done so you can still turn on the view state of individual control by <asp:TextBox runat="server" ID="txtCallsMadeFrom" class="field" ViewStateMode="Enabled">

like image 31
Jishnu A P Avatar answered Oct 07 '22 13:10

Jishnu A P