我在我的 asp.net 3.5 应用程序中使用了 Ajax 日历扩展器控件(来自 here )。
我的问题:如何从代码隐藏文件中的 Ajax 日历扩展器控件获取所选日期?
例如,我从日历中选择 01/01/2011,那么我需要在代码后面添加此日期,因为我需要检查空值。
如有任何疑问,请告诉我。
请指导。谢谢!
已使用代码更新问题
<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>
隐藏代码 (.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;
}
最佳答案
不要在 TextBox 上设置属性 ReadOnly="true"。
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.
关于asp.net - 获取ajax日历扩展器控件的选定日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7315376/