2011-06-30 36 views

回答

4

如果我想創建一個文本框格式的代碼背後,我們簡單的創建例如

TextBox txtDate = new TextBox(); 
     txtDate.ID = "txtDate"; 
     phDate.Controls.Add(txtDate); // here phDate is a Place holder on Aspx Page 
     //Now we need to add a Ajax Calendar Extender at Text Box so we should add Calendar dynamically on the code behind. 



AjaxControlToolkit.CalendarExtender calenderDate = new AjaxControlToolkit.CalendarExtender(); 
     calenderDate.ID = "calenderDate"; 
     calenderDate.TargetControlID = "txtDate"; 
     calenderDate.Format = "dd/MM/yyy"; 
     phDate.Controls.Add(calenderDate);] 
+0

文本框的對象起初我還以爲這是最初的海報問題的一部分,所以我貼一個答案,但我最終測試了你的代碼。你的代碼對我來說工作得很好。我不得不使用工具包腳本管理器控件。如果我使用普通的腳本管理器控件,這對我來說不起作用,這可能是正常的。 –

+0

是的,你必須使用「ToolkitScriptManager」,並接受答案,如果你有解決方案。 – Saurabh