Search code examples
asp.netajaxasp.net-ajaxajaxcontroltoolkit

Get selected date of ajax calendar extender control


I have used Ajax Calendar extender control (from here) in my asp.net 3.5 application.

My Question: How can i get the selected date from the Ajax calendar extender control in code behind file?

Say for example i am selecting 01/01/2011 from calendar, then i need this date in code behind, as i need to check for null values.

let me know for any query.

Please guide. Thanks!

Question updated with code

 &nbsp; <asp:Label ID="lblStartDate" runat="server" Text="<%$ Resources:Resource, lblStartDate %>" CssClass="boldlabelText"></asp:Label>
                                        &nbsp;<asp:TextBox ID="txtStartDate" runat="server" ReadOnly="true" MaxLength="10"></asp:TextBox>
                                        <asp:ImageButton runat="Server" ID="imgStartDate" ImageUrl="~/Images/Calender.png" AlternateText="Click to show calendar" />
                                        <ajax:CalendarExtender ID="CalStartDate" runat="server" TargetControlID="txtStartDate" Format="yyyy-MM-dd" PopupButtonID="imgStartDate">
                                        </ajax:CalendarExtender>

Code-Behind (.cs)

if (txtStartDate.Text.Equals(string.Empty))  // The text value always comes null
        {
            lblStartDateM.Visible = true; 
            txtStartDate.BackColor = Color.FromArgb(255, 255, 235);
            blnIsValid = false;
        }

Solution

  • Dont set the property ReadOnly="true" on your TextBox.

    From Joteke's Blog

    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.