{"id":8,"date":"2008-02-27T23:49:30","date_gmt":"2008-02-27T23:49:30","guid":{"rendered":"http:\/\/jcrawfor74.wordpress.com\/2008\/02\/27\/dynamically-creating-user-controls-in-code-behind\/"},"modified":"2013-01-24T02:07:50","modified_gmt":"2013-01-23T15:07:50","slug":"dynamically-creating-user-controls-in-code-behind","status":"publish","type":"post","link":"https:\/\/ntsblog.homedev.com.au\/index.php\/2008\/02\/27\/dynamically-creating-user-controls-in-code-behind\/","title":{"rendered":"Dynamically creating user controls in code behind"},"content":{"rendered":"<div id=\"ntsbl-2386338023\" class=\"ntsbl-before-content ntsbl-entity-placement\"><script async src=\"\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js?client=ca-pub-6288941070289539\" crossorigin=\"anonymous\"><\/script><ins class=\"adsbygoogle\" style=\"display:inline-block;width:728px;height:90px;\" \ndata-ad-client=\"ca-pub-6288941070289539\" \ndata-ad-slot=\"9356781486\"><\/ins> \n<script> \n(adsbygoogle = window.adsbygoogle || []).push({}); \n<\/script>\n<\/div><p>If you have a user control that you wish to dynamically add to your page the following will not work;<br \/>\n[csharp]<br \/>\nUserControl control = new UserControl()<br \/>\n[\/csharp]<br \/>\nThe problem is that the control has not been successfully created and all the internal controls that make up the user control, like text boxes etc, will be null.<\/p>\n<p>The way to create the control is with the &#8220;LoadControl()&#8221; statement.<br \/>\n[csharp]<br \/>\nUserControl control = LoadControl(&quot;~\/controls\/UserControl.ascx&quot;) as UserControl;<br \/>\n[\/csharp]<br \/>\nand now it will work.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you have a user control that you wish to dynamically add to your page the following will not work; [csharp] UserControl control = new [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[5,6],"tags":[31,18],"class_list":["post-8","post","type-post","status-publish","format-standard","hentry","category-c","category-code","tag-c","tag-user-controls"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/ntsblog.homedev.com.au\/index.php\/wp-json\/wp\/v2\/posts\/8","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ntsblog.homedev.com.au\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ntsblog.homedev.com.au\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ntsblog.homedev.com.au\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/ntsblog.homedev.com.au\/index.php\/wp-json\/wp\/v2\/comments?post=8"}],"version-history":[{"count":0,"href":"https:\/\/ntsblog.homedev.com.au\/index.php\/wp-json\/wp\/v2\/posts\/8\/revisions"}],"wp:attachment":[{"href":"https:\/\/ntsblog.homedev.com.au\/index.php\/wp-json\/wp\/v2\/media?parent=8"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ntsblog.homedev.com.au\/index.php\/wp-json\/wp\/v2\/categories?post=8"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ntsblog.homedev.com.au\/index.php\/wp-json\/wp\/v2\/tags?post=8"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}