Question

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

my .CS code is as follow:

protected void btnsave_Click(object sender, EventArgs e)
{
    DateTime bdate = DateTime.ParseExact(txtBirthDate.Text, "dd/MM/yyyy", null);
}

my .aspx code for calender control:

<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>
Was it helpful?

Solution

You should not set the property ReadOnly="true" on your TextBox.

If TextBox's ReadOnly property is "true", postback data won't be loaded e.g 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.

OTHER TIPS

before <asp:Content> add this line

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>

After <asp:Content> add

<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. Setting SelectedDate sets the textbox field at the same time.

Easy fix example

'protected void txDate_TextChanged(object sender, EventArgs e)
{ 
        txDate_CalendarExtender.SelectedDate = Convert.ToDateTime(txDate.Text);
}'
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top