0

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>
Alex
  • 1,110
  • 8
  • 15
shweta
  • 319
  • 2
  • 8
  • 21

4 Answers4

3

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.

Community
  • 1
  • 1
Govinda Rajbhar
  • 2,926
  • 6
  • 37
  • 62
0

Why don't you set the date time format in .cs file itself. Look here http://msdn.microsoft.com/en-us/library/system.windows.forms.datetimepicker.customformat%28v=vs.110%29.aspx

Adwait
  • 23
  • 6
  • 1
    :Hi,thanks for your reply but dateformat is not an issue here...i am not getting calender selected date in my text-box at runtime – shweta Jan 23 '14 at 06:41
0

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>
Shreyas Achar
  • 1,407
  • 5
  • 36
  • 63
0

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);
}'
All_IN
  • 11
  • 3