I am trying to add controls to the Dialog control dynamically. I add the controls to the ContentPane.TemplateControl.Controls collection. Whenever I do this, the control ends up on the page hosting the dialog and not in the dialog.
Is there something I need to do to get it to show up in the dialog correctly?
-Daniel
Thank you, that did what I expected. There is one thing I don't understand though. If I add controls dynamically this way, you can not also add additional controls via the design surface.
Here is an example of what I am talking about. I inerit from the webdialogwindow and add some buttons. Another developer can then drop this new control on the design surface and start adding controls to the markup. The problem is that none of the new controls show up. If I skip over adding the buttons, then the additional controls will show up.
So I can only seem to get one or the other. Is there a way to allow developers to use the new control on the design surface and still add controls dynamically?
Thanks again for you help.
Daniel,
Looks like you're adding the control to the wrong controls collection. You'll want to use the ConentPane.Controls collection instead. That's why your control isn't showing up in the content area of the Dialog Window. Also, here's a quick tip for extending one of our controls in this type of scenario- use the CreateChildControls override. I'm not sure if this was what you were already doing, but it's the recommended approach. Here's a quick example:
public class MyDialog : WebDialogWindow{ protected override void CreateChildControls() { base.CreateChildControls(); TextBox tb = new TextBox(); tb.ID = "tb1"; tb.Text = "text"; this.ContentPane.Controls.Add(tb); }}
Thanks for the response.
The problem is I want to inherit from the Dialog control and add my standard controls to the inherited class. Is this something that can be done with the dialog control? If not then I will just end up creating my own .ascx control which contains the dialog, but I was hoping to inherit from it instead.
The sure fire way to add a control at runtime is to first add a placeholder control at Design-time. If you add the PlaceHolder control in the Dialog box at design-time, you can simply add your control to the PlaceHolder control's .Controls collection.
If your child control is still not showing up in the right place, my guess is that you have a CSS issue - ie. your child control is absolutely positioned, which is making it appear outside of the bounds of its container.
-Tony