Get selected date of ajax calendar extender control
Solution 1
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.
Solution 2
You can also access the ReadOnly text box content via Request.Form collections:
Request.Form[txtStartDate.UniqueID]
has the same effect as
txtStartDate.text
Solution 3
Try this code. I have used this piece of code in my website and it is working fine. On button click event, I am able to get the date value entered in the textbox using .text property of textbox.
<asp:TextBox ID="txtDateFrom" runat="server" Width="70px"></asp:TextBox>
<ajax:CalendarExtender ID="CalendarExtender1" runat="server" CssClass="MyCalendar" Format="MM/dd/yyyy" TargetControlID="txtDateFrom" Enabled="True"></ajax:CalendarExtender>
<ajax:MaskedEditExtender ID="MaskedEditExtender1" runat="server" AcceptNegative="Left" DisplayMoney="Left" ErrorTooltipEnabled="True" InputDirection="RightToLeft" Mask="99/99/9999" MaskType="Date" TargetControlID="txtTranDateFrom" CultureAMPMPlaceholder="" CultureCurrencySymbolPlaceholder="" CultureDateFormat="" CultureDatePlaceholder="" CultureDecimalPlaceholder="" CultureThousandsPlaceholder="" CultureTimePlaceholder="" Enabled="True"></ajax:MaskedEditExtender>
xorpower
Reached 500 Repo on May 22'11 Reached 600 Repo on Jul 29'11 Reached 700 Repo on Aug 10'11 Reached 800 Repo on Sep 09'11 Reached 900 Repo on Oct 13'11 Reached (& crossed) 1000 Repo during Mar 14-19'12 Reached 1300 Repo on May 8 2013
Updated on June 02, 2020Comments
-
xorpower almost 4 years
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
<asp:Label ID="lblStartDate" runat="server" Text="<%$ Resources:Resource, lblStartDate %>" CssClass="boldlabelText"></asp:Label> <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; }
-
xorpower over 12 yearsi have used that. the value always comes null, even if date is selected
-
Bassetassen over 12 years@Xor power Can you post your code and markup where you use this so we can have a look at it?
-
xorpower over 12 yearsonkeypress event (of textbox) does fulfill my requirement?
-
xorpower over 12 years.text property of textbox always gives null value (as mention in question). Give supportive links
-
xorpower over 12 yearsBecause my textbox was in readonly mode (readonly=true) the values were not being fetched
-
Bipul Roy over 6 yearsThanks a lot, its helped me a lot