tags:

views:

225

answers:

3

Hi,

I have used JQuery within my asp.net page. JQuery is working fine. I could see the calendar and can pickup the date. The problem is that when the page is postbacked the value is lost. Am i missing some code? Does anyone of you have the idea?

Below is what i have done -

1) Included the files -

<script src="../scripts/date.js" type="text/javascript"></script>
<script src="../scripts/jquery.datePicker.js" type="text/javascript"></script>

<link href="../css/DatePicker.css" rel="stylesheet" type="text/css" />
<link href="../css/DateCalendar.css" rel="stylesheet" type="text/css" />

2) Linked with the textboxes -

jQuery(function($){           
     Date.format = 'mm/dd/yyyy';
     $("#<%=txtAssignDate.ClientID%>").datePicker({startDate:'01/01/1996'});
     $("#<%=txtCloseFileDate.ClientID%>").datePicker({startDate:'01/01/1996'});
     $("#<%=txtInspectionDt.ClientID%>").datePicker({startDate:'01/01/1996'});
});
A: 

If the datepicker is working fine and selecting a value, you probably forgot to tell the text field to retain it's value on postback. If you're using Visual Studio/Visual Web Developer, one of the properties of the textfield object is "EnableViewState", which should be set to true.

Mike Trpcic
Thanks Mike, but EnaleViewState is already true for all objects.
IrfanRaza
A: 

Here is my test code:

aspx:

<script type="text/javascript" src="/js/jquery-1.3.2.js"></script>
<script src="/js/date.js" type="text/javascript"></script>
<script src="/js/jquery.datePicker.js" type="text/javascript"></script>
<link href="/css/datePicker.css" rel="stylesheet" type="text/css" />

<form id="form1" runat="server">
    Date: <asp:TextBox ID="txtDate" runat="server" /><br />
    <asp:Button ID="btnSubmit" Text="Click" runat="server" OnClick="btnClick" />
</form>

C#:

    protected void btnClick(object sender, EventArgs e)
    {}

and it's working perfectly. Please check if you are running some code on postback which is resetting the field.

TheVillageIdiot
Thanks buddy!!! but i have checked all code, there is not a single place where date is resetting.
IrfanRaza
A: 

Hi guys,

I found the reason. The problem was because of masking. I have also used the JQuery masking. I found the dates are saved in database but while displaying the dates within text fields it was wipe off the values having single digit because of masking mm/dd/yyyy. For ex. 09/01/2009.

IrfanRaza