c# ASP.NET Controls collections code block nonsense -


what can cause:

the controls collection cannot modified because control contains code blocks (i.e. <% ... %>). 

i ask because, code not contain code blocks. anywhere. there not single <%= %> block on page in entire site. have <%@ %> directive lines.

edit:

below code causing error.

/// <summary> /// adds javascript variables page asp control id accessable via javascript. /// variable names asp_controlid. /// </summary> /// <param name="page">the page add javascript to</param> /// <param name="ctls">the controls make accessable</param> public static void addjavascriptids(page page, params control[] ctls) {     literal litjs = new literal();     litjs.text = getjavascriptids(ctls);     page.form.controls.add(litjs);  ////////// <-- error here }  /// <summary> /// returns string containing javascript allow javascript access /// asp controls. /// </summary> /// <param name="ctls">the html , javascript create javascript variables</param> /// <returns>the script</returns> public static string getjavascriptids(params control[] ctls) {     string js = "\n<script type=\"text/javascript\">\n";     foreach (control ctl in ctls)         js += "\tvar asp_" + ctl.id + " = '" + ctl.clientid + "';\n";     js += "</script>\n\n";      return js; } 

this page_load function:

protected void page_load(object sender, eventargs e) {     formhowhear.attributes.add("onchange", "displayother(this);");     loadvalues();     if (!ispostback)     {         loaddefaults();         bindvalidation();     }     else     {         submitted();     }     cmsutil.addjavascriptids(this, formemail1, formemail2, formusername);     cmsutil.addjavascriptincludes(page,         resolveurl("~/js/jquery-1.4.2.min.js"),         resolveurl("~/admin/js/tvcms.js")         ); } 

maybe have custom control contains <% %>, example ajaxcontroltoolkit calendar. had same problem once, , solution remove control.

try removing/commenting pieces of code can locate causes problem.

edit: not sure if corrects problem, correct way inject js:

public static void addjavascriptids(page page, params control[] ctls) {     string js = "";     foreach (control ctl in ctls)         js += string.format("var asp_{0} = '{1}';", ctl.id, ctl.clientid);     page.clientscript.registerclientscriptblock(typeof(object), "ids", js, true)     /* http://msdn.microsoft.com/en-us/library/bahh2fef.aspx */ } public static void addjavascriptincludes(page page, params string[] scripts) {     foreach (string script in scripts)         page.clientscript.registerclientscriptinclude(typeof(object), script, page.resolveurl(script));     /* http://msdn.microsoft.com/en-us/library/kx145dw2.aspx */ } 

Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -