{"id":3701,"date":"2014-03-29T08:10:07","date_gmt":"2014-03-29T08:10:07","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/29\/is-this-a-bug-in-asp-net-3-5-collection-of-common-programming-errors\/"},"modified":"2014-03-29T08:10:07","modified_gmt":"2014-03-29T08:10:07","slug":"is-this-a-bug-in-asp-net-3-5-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/29\/is-this-a-bug-in-asp-net-3-5-collection-of-common-programming-errors\/","title":{"rendered":"Is this a bug in ASP.NET 3.5?-Collection of common programming errors"},"content":{"rendered":"<p>In ASP.NET when I try to add a dynamic control (includes validation) to <code>Placeholder<\/code> or any other control container, the name of control become an important. For example, this is very normal, easy control adding code.<\/p>\n<pre><code>var control = LoadControl(\"TestUserControl.ascx\");\ncontrol.ID = Guid.NewGuid().ToString();\nPlaceHolder1.Controls.Add(control);\n<\/code><\/pre>\n<p>as you see, I&#8217;m giving guid to control&#8217;s ID. In Runtime, this code fails, and compiler says this is a javascript error, and error message like &#8216;;&#8217; character expected, missing.. etc..<\/p>\n<p>The problem is very interesting. Dynamically added ASP.NET control (includes validation), causes an error because of &#8221; &#8211; &#8221; character in dynamically named ID property (or anything like &#8216;-&#8216;, &#8216;.&#8217;,etc..).<\/p>\n<p>When I refine my code like:<\/p>\n<pre><code>var control = LoadControl(\"TestUserControl.ascx\");\ncontrol.ID = Guid.NewGuid().ToString().Replace(\"-\", string.Empty);\nPlaceHolder1.Controls.Add(control);\n<\/code><\/pre>\n<p>problem goes away \ud83d\ude42<\/p>\n<p>Is this a bug in <strong>ASP.NET 3.5<\/strong>? Why its look like a javascript error in page?<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In ASP.NET when I try to add a dynamic control (includes validation) to Placeholder or any other control container, the name of control become an important. For example, this is very normal, easy control adding code. var control = LoadControl(&#8220;TestUserControl.ascx&#8221;); control.ID = Guid.NewGuid().ToString(); PlaceHolder1.Controls.Add(control); as you see, I&#8217;m giving guid to control&#8217;s ID. In Runtime, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-3701","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/3701","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=3701"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/3701\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=3701"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=3701"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=3701"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}