![](/img/trans.png)
[英]AJAX Calendar Extender - binding null to text as selected date
[英]Get selected date of ajax calendar extender control
我在我的asp.net 3.5應用程序中使用了Ajax Calendar擴展程序控件(從這里開始 )。
我的問題:如何從代碼隱藏文件中的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” 。
如果TextBox的ReadOnly屬性為“true”,則不會加載回發數據,例如,它實質上意味着TextBox從服務器端的角度來看只讀(客戶端更改將被忽略)。 如果你想以“舊方式”使用TB只讀
TextBox1.Attributes.Add("readonly","readonly")
因為這不會影響服務器端功能。
您還可以通過Request.Form集合訪問ReadOnly文本框內容:
的Request.Form [txtStartDate.UniqueID]
具有相同的效果
txtStartDate.text
參考: http : //www.aspsnippets.com/Articles/ASP.Net-AJAX-CalendarExtender---Get-selected-date-from-ReadOnly-TextBox.aspx
試試這個代碼。 我在我的網站上使用了這段代碼並且工作正常。 在按鈕單擊事件上,我可以使用textbox的.text屬性獲取在文本框中輸入的日期值。
<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>
不幸的是,如果intellisense沒有檢測到文本框或者嵌入GridView中的文本框,那么在Page_Load()事件的文本框控件中設置ReadOnly
屬性是沒用的。
因此,為了避免所有這些問題,我只需將TextBox控件轉換為“psuedo”標簽控件,並且仍然可以在“標簽”上使用AjaxControlToolKit CalendarExtender
把onKeyPress = "javascript: return false;" onPaste = "javascript: return false;"
onKeyPress = "javascript: return false;" onPaste = "javascript: return false;"
在你的文本框中。 這樣,即使文本框已啟用,用戶也無法修改數據,並且您迫使他們使用Calendar控件,這實際上就是您想要的。 我們不應該讓用戶輸入日期。
使用文本框中由calenderextender“擴展”的text屬性
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.