开发者

JQuery Datepicker issue - asp.net

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(f开发者_StackOverflow中文版unction($){           
        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'});
});


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.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜