2011-08-11 5 views
0

JavaScriptでAJAXツールキットを使用してASP.NET Webページにカレンダーを実装しようとしていますが、動的にテキストボックスを作成してポップアップカレンダーを作成しています。コードは以下の通りである: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

マスターページのヘッドにコードブロックを書き込もうとしている場合は、< %%>をご覧ください。これは私の同じ問題に対する答えでした。

関連する問題