[英]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.