JQuery Datepicker issue - asp.net

I have used JQuery in my asp.net page. JQuery works fine. I could see the calendar and write down the date. The problem is that when the page is forwarded, the value is lost. Am I missing some code? Do any of you have an idea?

Below I have done -

1) Files included -      

<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) Related to text fields -

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'});
});

      

+2


source to share


3 answers


I found the reason. The problem was disguise. I have also used JQuery masking. I found that dates are stored in the database, but when displaying dates in text fields, it cleared out values โ€‹โ€‹having one digit, due to the mm / dd / yyyy masking. Ex. 09/01/2009.



0


source


If the datepicker function works fine and picks a value, you probably forgot to specify the textbox to store its value on postback. If you are using Visual Studio / Visual Web Developer, one of the properties of the textfield object is "EnableViewState", which should be set to true.



0


source


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>

      

FROM#:

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

      

and it works great. Check if any code is running on postback

that resets the field.

0


source







All Articles