[英]Date selected from calendar control doesn't change in Textbox at runtime
I have to save date selected from ajax calender control,when i select date from ajax calender control it shows in textbox,but when i save this date i got the previous value of date not the cureently selected value,i have written this code on btnsave_Click event我必须保存从 ajax 日历控件中选择的日期,当我从 ajax 日历控件中选择日期时,它会显示在文本框中,但是当我保存这个日期时,我得到的是日期的先前值而不是当前选择的值,我在 btnsave_Click 上编写了此代码事件
my .CS code is as follow:我的 .CS 代码如下:
protected void btnsave_Click(object sender, EventArgs e)
{
DateTime bdate = DateTime.ParseExact(txtBirthDate.Text, "dd/MM/yyyy", null);
}
my .aspx code for calender control:我用于日历控制的 .aspx 代码:
<td>
<asp:TextBox ID="txtBirthDate" runat="server" ReadOnly="true" CssClass="Txtprop" ></asp:TextBox>
<cc1:CalendarExtender ID="calDOB" runat="server" TargetControlID="txtBirthDate" Format="dd/MM/yyyy" ></cc1:CalendarExtender>
</td>
You should not set the property ReadOnly="true" on your TextBox.您不应在 TextBox 上设置属性ReadOnly="true" 。
If TextBox's ReadOnly property is "true", postback data won't be loaded eg it essentially means TextBox being readonly from server-side standpoint (client-side changes will be ignored). If you want TB to be readonly in the "old manner" use
TextBox1.Attributes.Add("readonly","readonly")
as that won't affect server-side functionality.因为这不会影响服务器端功能。
For more information follow StackoverflowAnswer or TextBox Readonly problem.有关更多信息,请关注StackoverflowAnswer或TextBox Readonly问题。
Why don't you set the date time format in .cs file itself.为什么不在 .cs 文件本身中设置日期时间格式。 Look here http://msdn.microsoft.com/en-us/library/system.windows.forms.datetimepicker.customformat%28v=vs.110%29.aspx看这里http://msdn.microsoft.com/en-us/library/system.windows.forms.datetimepicker.customformat%28v=vs.110%29.aspx
before <asp:Content>
add this line在<asp:Content>
添加这一行
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
After <asp:Content
> add在<asp:Content
> 之后添加
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</asp:ToolkitScriptManager>
To solve this set the CalendarExtender's SelectedDate in the textbox.Text data = change to whatever it is in the textbox and it will stick.为了解决这个问题,在文本框中设置 CalendarExtender 的 SelectedDate。Text data = 更改为文本框中的任何内容,它会坚持下去。 Setting SelectedDate sets the textbox field at the same time.设置 SelectedDate 同时设置文本框字段。
Easy fix example简单修复示例
'protected void txDate_TextChanged(object sender, EventArgs e)
{
txDate_CalendarExtender.SelectedDate = Convert.ToDateTime(txDate.Text);
}'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.