{"action":"created","issue":{"url":"https://api.github.com/repos/webformsmvp/webformsmvp/issues/4","repository_url":"https://api.github.com/repos/webformsmvp/webformsmvp","labels_url":"https://api.github.com/repos/webformsmvp/webformsmvp/issues/4/labels{/name}","comments_url":"https://api.github.com/repos/webformsmvp/webformsmvp/issues/4/comments","events_url":"https://api.github.com/repos/webformsmvp/webformsmvp/issues/4/events","html_url":"https://github.com/webformsmvp/webformsmvp/issues/4","id":228370335,"number":4,"title":"Presenter didn't bound on user controls when loaded dynamically using control events","user":{"login":"gedeh","id":6280668,"avatar_url":"https://avatars0.githubusercontent.com/u/6280668?v=3","gravatar_id":"","url":"https://api.github.com/users/gedeh","html_url":"https://github.com/gedeh","followers_url":"https://api.github.com/users/gedeh/followers","following_url":"https://api.github.com/users/gedeh/following{/other_user}","gists_url":"https://api.github.com/users/gedeh/gists{/gist_id}","starred_url":"https://api.github.com/users/gedeh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gedeh/subscriptions","organizations_url":"https://api.github.com/users/gedeh/orgs","repos_url":"https://api.github.com/users/gedeh/repos","events_url":"https://api.github.com/users/gedeh/events{/privacy}","received_events_url":"https://api.github.com/users/gedeh/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2017-05-12T18:21:39Z","updated_at":"2017-05-17T13:12:22Z","closed_at":null,"body":"Hi Tatham,\r\n\r\nI found issue when user control is loaded and added dynamically under control events on server side code.\r\n\r\nFor example, using your `ViewsAddedInPageInit` sample page. I added a button with ID `LoadDynamicControl`, the button `OnClick` attribute is `LoadDynamicControl_OnClick`. So the page becomes like this:\r\n```\r\n<%@ Page Title=\"\" Language=\"C#\" MasterPageFile=\"~/Layout/Site.Master\" AutoEventWireup=\"true\" CodeBehind=\"ViewsAddedInPageInit.aspx.cs\" Inherits=\"WebFormsMvp.FeatureDemos.Web.ViewsAddedInPageInit\" %>\r\n<asp:Content ID=\"Content1\" ContentPlaceHolderID=\"head\" runat=\"server\">\r\n</asp:Content>\r\n<asp:Content ID=\"Content2\" ContentPlaceHolderID=\"content\" runat=\"server\">\r\n    <h1>View User Controls Being Added in Page_Init</h1>\r\n    <p>This page demonstrates a user control with a declared presenter binding being dynamically loaded\r\n       into the page during the Page_Init phase. This is a common scenario in CMS platforms, e.g. DNN.</p>\r\n    <asp:Button runat=\"server\" Text=\"Load control\" ID=\"LoadDynamicControl\" OnClick=\"LoadDynamicControl_OnClick\"/>\r\n    <asp:Panel ID=\"dynamicallyLoadedControlsPlaceholder\" runat=\"server\"></asp:Panel>\r\n</asp:Content>\r\n```\r\n\r\nThen  in code behind:\r\n1. I removed code to load control dynamically inside `Page_Init` method\r\n2. I assign `OnClick` event to `LoadDynamicControl` like below\r\n\r\n```\r\nprotected void LoadUserControl_OnClick(object sender, EventArgs e)\r\n{\r\n    Page.LoadControl(\"~/Controls/CustomUserControl.ascx\")\r\n    dynamicallyLoadedControlsPlaceholder.Controls.Add(_contactNotesUserControl)\r\n}\r\n```\r\n\r\nAfter I click `LoadDynamicControl` button is, in page `ViewsAddedInPageInit.aspx` the message `If this content is visible, there was a problem in binding the dynamically loaded control's presenter.` is shown, which means Presenter is not properly bound to the user control.\r\n\r\nCan you suggest how to load dynamic control based on events like above scenario? I understand that its best to not load user control and add it after `Page_Init` to avoid View State misuse. But although I use `Page_Init` to load the control then add it to `dynamicallyLoadedControlsPlaceholder` in `LoadUserControl_OnClick`. The same issue also occurs.\r\n\r\nThanks,\r\nHendra"},"comment":{"url":"https://api.github.com/repos/webformsmvp/webformsmvp/issues/comments/302085585","html_url":"https://github.com/webformsmvp/webformsmvp/issues/4#issuecomment-302085585","issue_url":"https://api.github.com/repos/webformsmvp/webformsmvp/issues/4","id":302085585,"user":{"login":"gedeh","id":6280668,"avatar_url":"https://avatars0.githubusercontent.com/u/6280668?v=3","gravatar_id":"","url":"https://api.github.com/users/gedeh","html_url":"https://github.com/gedeh","followers_url":"https://api.github.com/users/gedeh/followers","following_url":"https://api.github.com/users/gedeh/following{/other_user}","gists_url":"https://api.github.com/users/gedeh/gists{/gist_id}","starred_url":"https://api.github.com/users/gedeh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gedeh/subscriptions","organizations_url":"https://api.github.com/users/gedeh/orgs","repos_url":"https://api.github.com/users/gedeh/repos","events_url":"https://api.github.com/users/gedeh/events{/privacy}","received_events_url":"https://api.github.com/users/gedeh/received_events","type":"User","site_admin":false},"created_at":"2017-05-17T13:12:21Z","updated_at":"2017-05-17T13:12:21Z","body":"Hi @tathamoddie who else I can contact regarding this issue? Or scenario described above simply not supported?"}}
{"actor":{"display_login":"gedeh"}}