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
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 to share
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 to share