2011-08-11 48 views
0

我想在我的ASP.NET網頁中使用JavaScript中的AJAX工具包實現日曆,以便動態創建文本框並使用彈出日曆填充它。代碼如下:使用Ajax工具包的日曆

for(var j=1; j<2;j++) 
{ 
    <asp:ToolkitScriptManager runat="server"></asp:ToolkitScriptManager> 
    <input type="text" ID="startDate"+j runat="server" BackColor="#D6E4ED" 
     BorderStyle="Inset" Width="10px" ></input> 
    <asp:CalendarExtender runat="server" TargetControlID="startDate"+j> 

} 

查看瀏覽器的給下面的錯誤後:

The control collection cannot be modified during DataBind, Init, Load, PreRender or Unload phases. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

異常詳細信息:

System.Web.HttpException: The control collection cannot be modified during DataBind, Init, Load, PreRender or Unload phases. 

源錯誤:

An unhandled exception was generated during the execution of the current web request. 
Information regarding the origin and location of the exception can be identified using the exception stack trace below. 

堆棧跟蹤:

[HttpException (0x80004005): The control collection cannot be modified during DataBind, Init, Load, PreRender or Unload phases.]
System.Web.UI.ControlCollection.Add(Control child) +8677431
AjaxControlToolkit.ScriptObjectBuilder.RegisterCssReferences(Control control) in C:\Users\Stephen\Documents\Repos\Superexpert\AjaxControlToolkit\Server\AjaxControlToolkit\ExtenderBase\ScriptObjectBuilder.cs:323 AjaxControlToolkit.ExtenderControlBase.OnLoad(EventArgs e) in C:\Users\Stephen\Documents\Repos\Superexpert\AjaxControlToolkit\Server\AjaxControlToolkit\ExtenderBase\ExtenderControlBase.cs:305 System.Web.UI.Control.LoadRecursive() +50
System.Web.UI.Control.LoadRecursive() +141
System.Web.UI.Control.LoadRecursive() +141
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627

請提出一些建議來解決問題。

回答

0

看看你是否試圖在你的母版頁頭<%>中寫入代碼塊。這是我同樣問題的答案。