Adding Controls to a custom user controlhttp://forums.asp.net/t/1220091.aspx/1?Adding+Controls+to+a+custom+user+controlFri, 15 Feb 2008 17:57:32 -050012200912174160http://forums.asp.net/p/1220091/2174160.aspx/1?Adding+Controls+to+a+custom+user+controlAdding Controls to a custom user control <p>I am trying to make a &quot;template&quot; control that can be used as a fake window.</p> <p>So it have a title bar, title icon and close button. </p> <p>I have the control created, but when i add it to the aspx page I can not drag a button into the control. </p> <p>&nbsp;</p> <p>Control code </p> <p>&nbsp;&lt;%@ Control Language=&quot;C#&quot; AutoEventWireup=&quot;true&quot; CodeFile=&quot;webWindow.ascx.cs&quot; Inherits=&quot;webWindow&quot;&nbsp; %&gt;<br> <br> &lt;link href=&quot;StyleSheet.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot; /&gt;<br> &lt;asp:Panel ID=&quot;webWindowPan&quot; runat=&quot;server&quot; cssClass=&quot;modalPopup&quot;&nbsp; Width=&quot;500px&quot; &gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;table&nbsp; class=&quot;titleBar&quot; border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot;&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;tr&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;td&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;asp:Image ID=&quot;webWindowTitleIcon&quot; runat=&quot;server&quot; Height=&quot;16px&quot; ImageUrl=&quot;~/images/application.png&quot; Width=&quot;16px&quot; /&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;asp:Label ID=&quot;webWindowTitle&quot; runat=&quot;server&quot; Font-Bold=&quot;True&quot; Text=&quot;New Web Window&quot; ForeColor=&quot;White&quot; BackColor=&quot;Transparent&quot; Height=&quot;20px&quot;&gt;&lt;/asp:Label&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/td&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;td width=&quot;20&quot; &gt;&amp;nbsp;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/td&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;td align=&quot;right&quot; style=&quot;width: 55px&quot;&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;asp:ImageButton ID=&quot;webWindowCloseButton&quot; runat=&quot;server&quot; Height=&quot;16px&quot; ImageUrl=&quot;~/images/close_gray.png&quot;&nbsp; Width=&quot;40px&quot;&nbsp; /&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/td&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/tr&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/table&gt; <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;asp:Panel ID=&quot;webWindowContent&quot; runat=&quot;server&quot; Width=&quot;100%&quot; &gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Hello<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/asp:Panel&gt;<br> &lt;/asp:Panel&gt;</p> <p>&nbsp;</p> <p>&nbsp;</p> <p>ASPX Code -</p> <p>&lt;%@ Register src=&quot;webWindow.ascx&quot; TagName=&quot;webWindow&quot; TagPrefix=&quot;uc1&quot;&nbsp; %&gt;&nbsp;</p> <p>&nbsp;&nbsp;&nbsp;&nbsp; &lt;form id=&quot;form1&quot; runat=&quot;server&quot;&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;ajaxToolkit:ToolkitScriptManager ID=&quot;ScriptManager1&quot; runat=&quot;server&quot; /&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;div&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;uc1:webWindow id=&quot;WebWindow1&quot; runat=&quot;server&quot;&nbsp;&nbsp;&nbsp; &gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/uc1:webWindow&gt;&lt;/div&gt;<br> &nbsp;&nbsp;&nbsp; &lt;/form&gt;</p> <p>&nbsp;</p> <p>I have been searching and can't figure out how to edit the usercontrol in the aspx page to add content to the &quot;window&quot;&nbsp;</p> <p>Thank you&nbsp;</p> 2008-02-14T20:08:56-05:002174200http://forums.asp.net/p/1220091/2174200.aspx/1?Re+Adding+Controls+to+a+custom+user+controlRe: Adding Controls to a custom user control <p>Try this in the Page_Load method of your .aspx page: &nbsp;<pre class="prettyprint">Button btnNewButton = new Button(); WebWindow1.Controls.Add(btnNewButton);</pre> </p> <p>&nbsp;Hope this provides some insight.</p> <p>- Jesse</p> 2008-02-14T20:27:33-05:002174219http://forums.asp.net/p/1220091/2174219.aspx/1?Re+Adding+Controls+to+a+custom+user+controlRe: Adding Controls to a custom user control <p>&nbsp;Thank you Jesse, </p> <p>This is a project that several people from my team are working on. What I am wanting to do is allow them to create a page then drag the custom control on to their page and drag controls inside the custom control. I am not sure if this is even possible. If it is not I will probably just step back and keep reproducing the code on each page needed rather than use the user control. <br> &nbsp;</p> 2008-02-14T20:35:44-05:002175641http://forums.asp.net/p/1220091/2175641.aspx/1?Re+Adding+Controls+to+a+custom+user+controlRe: Adding Controls to a custom user control <p>Anyone else have any ideas?&nbsp;</p> 2008-02-15T12:20:55-05:002175776http://forums.asp.net/p/1220091/2175776.aspx/1?Re+Adding+Controls+to+a+custom+user+controlRe: Adding Controls to a custom user control <p>Sorry about, didn't get a chance to get on the computer last night after work.</p> <p>I see what your issue is, you are correct, you cannot 'drag and drop' additional controls onto a control in the Visual Studio Designer.&nbsp; My next question is, do you know what controls the other developers would be adding?&nbsp; In my opinion it would seem a little overhead to manually add the controls to your control everytime there is a page load.</p> <p>If you know what the other developers need you could always create additional user controls that they could then drag and drop onto the page as needed.&nbsp; The controls will be able to communicate with one another.&nbsp; Also, you start developing your own framework on top of .NET.</p> <p>Hope this helps a little more.</p> <p>- Jesse</p> 2008-02-15T13:25:33-05:002175987http://forums.asp.net/p/1220091/2175987.aspx/1?Re+Adding+Controls+to+a+custom+user+controlRe: Adding Controls to a custom user control <p>Sorry Jesse, </p> <p>&nbsp;I don't think my original post was very clear. I have gone in a slightly different direction. Same basic idea, but using Templates inside a user control. <br> </p> <p>I am looking for something like this </p> <p>http://wss3.theseders.com/robsederblog/Lists/Posts/Post.aspx?List=4c9e886c%2D4b5c%2D4a3e%2D95a0%2De30b3f4a1e9c&amp;ID=67</p> <p>But I am getting an error on this that says &quot;Type 'System.Web.UserControl' does not have a public property named 'ContentTemplate'</p> <p>However I do have :) </p> <p>&nbsp;[In the User Control]</p> <p>&nbsp;&nbsp;&nbsp;&nbsp; private ITemplate _windowContent;</p> <p>&nbsp;&nbsp;&nbsp; protected override void OnInit(EventArgs e)<br> &nbsp;&nbsp;&nbsp; {<br> <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; base.OnInit(e);<br> <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (_windowContent != null)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br> <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; _windowContent.InstantiateIn(webWindowContent);<br> <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br> <br> &nbsp;&nbsp;&nbsp; } <br> </p> <p>[PersistenceMode(PersistenceMode.InnerProperty), <br> &nbsp;&nbsp;&nbsp; TemplateContainer(typeof(TemplateControl))]<br> &nbsp;&nbsp;&nbsp; public ITemplate ContentTemplate<br> &nbsp;&nbsp;&nbsp; {<br> <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; get { return _windowContent; }<br> <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; set { _windowContent = value; }<br> <br> &nbsp;&nbsp;&nbsp; }<br> &nbsp;</p> 2008-02-15T14:44:31-05:002176096http://forums.asp.net/p/1220091/2176096.aspx/1?Re+Adding+Controls+to+a+custom+user+controlRe: Adding Controls to a custom user control <p>&nbsp;Found this also, </p> <p>http://msdn2.microsoft.com/en-us/library/36574bf6(VS.80).aspx</p> <p>My issue is getting it to somehow show up in the designer. </p> <p>I tried the things in teh comments from the above page, but it doesn't change the results I am getting. &nbsp;</p> 2008-02-15T15:27:29-05:002176357http://forums.asp.net/p/1220091/2176357.aspx/1?Re+Adding+Controls+to+a+custom+user+controlRe: Adding Controls to a custom user control <p>Thanks for the info!&nbsp; What is the markup in your user control (.ascx)?</p> <p>- Jesse</p> 2008-02-15T17:15:35-05:002176460http://forums.asp.net/p/1220091/2176460.aspx/1?Re+Adding+Controls+to+a+custom+user+controlRe: Adding Controls to a custom user control <p>&nbsp;I finally gave up and am just going to have the &quot;title bar&quot; be a user control. So I am not using the templates at all. I think this will get me what i need. Thank you Jesse for taking the time to help me. </p> <p>&nbsp;</p> 2008-02-15T17:57:32-05:00