简体   繁体   English

从日历控件中选择的日期在运行时不会在文本框中更改

[英]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.有关更多信息,请关注StackoverflowAnswerTextBox Readonly问题。

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.

相关问题 从月份日历控件中删除选定的日期 - Remove selected date from a month calendar control 日历选择的索引更改不会触发 - Calendar selected index change doesn't fire 如何将所选日期从AJAX日历控件传递到存储过程 - How to pass selected date from AJAX calendar Control into stored procedure C#(xaml)中的文本框的文本在运行时不会更改 - Text of a TextBox in C# (xaml) doesn't change at runtime 从文本框中获取价值的刷新日历控件 - Refreshing Calendar Control that gets value from Textbox Calendar Extendar没有显示一个文本框的开始日期到另一个文本框的选定日期 - Calendar Extendar is not showing Starting Date of one textbox to selected date of another textbox 从其他表单文本框调用功能不变 - Calling function from other form textbox doesn't change 从日历中选择日期到文本框 - selected date from calendar into text box 有人可以帮助我理解为什么选择 RadioButton 时我的 TextBox 的占位符没有改变吗? - Can someone help me understand why my TextBox's placeholder doesn't change when RadioButton selected? 我有一个基于TextBox的自定义控件,但是Text在TextChanged处理程序中没有更改 - I have a custom control based on TextBox, but the Text doesn't change in the TextChanged handler
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM