2017-07-08 13 views
0

我变得非常这段代码生气了:d我使用jQuery日期选择器在已设置为只读和日期选择器应在同一页面中出现两次,它取决于输入字段上的下拉列表的值。jQuery的日期选择器和asp.net C#空值

我使用的语言是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()); 

任何想法,为什么我通过日期选择器渐渐空虚日期,当我试图早期的教我正确地获得价值一情况下,只有:(

+0

与尝试'.value',而不是'.Text.Trim()' –

回答

1

在网络表单控件删除只读属性,并设置只读属性吨hrough的JavaScript。

<script type='text/javascript'> 
     $(function() { 
      $("#txt_check_chequeDate").attr("readonly", true); 
      $("#txt_wire_chequeDate").attr("readonly", true); 
     }) 
</script> 
+0

这解决了问题,太感谢你了。 –

1

在本post说试试这个:

txt_wire_chequeDate.Attributes.Add("readonly", "true"); 
txt_check_chequeDate.Attributes.Add("readonly", "true"); 

和除去Readonly = "true"

+0

谢谢你这么多 –