I created this asp.net user control (just a sample for this stack overflow post)
HTML:
<%@ Control Language="vb" AutoEventWireup="false" CodeBehind="ucBTN.ascx.vb" Inherits="EBC_SAK_MVV_BTN.web.ucBTN" %>
<div>
<asp:Button ID="btnLeft" runat="server" Width="200" Height="100" CssClass="btn btn-sq-lg btn-primary" Text="Button-Left" />
<asp:Button ID="btnMiddle" runat="server" Width="200" Height="100" CssClass="btn btn-sq-lg btn-primary" Text="Button-Middle" />
<asp:Button ID="btnRight" runat="server" Width="200" Height="100" CssClass="btn btn-sq-lg btn-primary" Text="Button-Right" />
</div>
Code behind:
Public Class ucBTN
Inherits System.Web.UI.UserControl
Public Property TextLeft As String
Public Property TextMiddle As String
Public Property TextRight As String
End Class
When I use this user control in a page it works (test.aspx):
<%@ Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/EBC.Master" CodeBehind="TEST.aspx.vb" Inherits="EBC_SAK_MVV_BTN.web.TEST" %>
<%@ Register Src="~/ucBTN.ascx" TagPrefix="uc1" TagName="ucBTN" %>
<uc1:ucBTN runat="server" ID="myBTN" />
But when I add a panel to my page and add my user control to this panel it keeps blank:
HTML:
<asp:Panel ID="Panel1" runat="server"></asp:Panel>
Code behind:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim BTN As New ucBTN
BTN.TextLeft = "LEFT"
BTN.TextMiddle = "MIDDLE"
BTN.TextRight = "RIGHT"
Panel1.Controls.Add(BTN)
End Sub
I want to create dozends of these controls during runtime - how do I add them to my panel?
in user control use:
<asp:PlaceHolder ID="PlaceHolder1" runat="server">
in code behind use:
PlaceHolder1.Controls.Add(BTN)