[英]jquery datepicker and asp.net c# empty value
我對這個代碼感到非常生氣:D我在設置為只讀的輸入字段中使用jQuery datepicker,並且datepicker應該在同一頁面中出現兩次,這取決於dropdownlist的值。
我使用的語言是ASP.NET c#:
我的aspx頁面上有以下輸入文本框:
<asp:TextBox ID="txt_check_chequeDate" runat="server" BorderStyle="Solid"
BorderWidth="2px" Font-Names="Calibri" Style="margin-left: 0px" ClientIDMode="Static" ReadOnly="true"></asp:TextBox>
<tr ID="tr_wire_TransactionDate" runat="server">
<td>
<asp:Label ID="lbl_wire_TransactionDate" runat="server" Font-Names="Calibri"
Text="Transaction Date"></asp:Label>
</td>
<td>
<asp:TextBox ID="txt_wire_chequeDate" runat="server" BorderStyle="Solid"
BorderWidth="2px" ClientIDMode="Static" Font-Names="Calibri"
Style="margin-left: 0px" ReadOnly="true"></asp:TextBox>
</td>
</tr>
和我的jQuery腳本如下參考:
<script type="text/javascript" src="../Scripts/jquery-1.4.1.min.js"></script>
<script src='../Scripts/jquery-1.4.1-vsdoc.js' type='text/javascript'></script>
<script src='../Scripts/jquery.ui.core.js' type='text/javascript'></script>
<script src='../Scripts/jquery.ui.widget.js' type='text/javascript'></script>
<link href='../Styles/jquery.ui.all.css' rel='stylesheet' type='text/css'/>
<link href='../Styles/jquery.ui.datepicker.css' rel='Stylesheet'
type='text/css' />
<script src='../Scripts/jquery.ui.datepicker.js' type='text/javascript'></script>
<script type='text/javascript'>
$(function () {
$('#txt_check_chequeDate').datepicker({ changeYear: true });
});
$(function () {
$('#txt_wire_chequeDate').datepicker({ changeYear: true });
});
當我單擊提交按鈕時,我將通過執行以下操作獲得空值:
Debug.WriteLine("on page click value is wire = " + this.txt_wire_chequeDate.Text.Trim());
Debug.WriteLine("on page click value is cheque = " + this.txt_check_chequeDate.Text.Trim());
不知道為什么我通過datepicker獲取空日期,當我嘗試伯爵時,我僅在一種情況下才正確獲取了值:(
刪除Webform控件上的readonly屬性,然后通過javascript設置readonly屬性。
<script type='text/javascript'>
$(function () {
$("#txt_check_chequeDate").attr("readonly", true);
$("#txt_wire_chequeDate").attr("readonly", true);
})
</script>
如這篇文章所述,請嘗試以下操作:
txt_wire_chequeDate.Attributes.Add("readonly", "true");
txt_check_chequeDate.Attributes.Add("readonly", "true");
並刪除Readonly = "true"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.