troubleshooting Question

Design time controls return nothing / null at runtime in ascx.

Avatar of cme0015
cme0015 asked on
ASP.NET.NET Programming
5 Comments1 Solution435 ViewsLast Modified:
Good afternoon,

Here is my problem.  I am working on a site wherein I need to be able to add complex objects at run-time to the aspx page.  To that end, I have been working with ASCX files and it seems to be the right direction, however, elements that I add at design time return nothing once I call a new UserControl from codebehind.  In the sample below, the control never shows in the browser and the uc.Label1 = nothing at runtime, please help and thank you in advance.

Simple code-sample below.

<%@ Control Language="vb" AutoEventWireup="false" CodeBehind="WebUserControl1.ascx.vb" Inherits="WebApplication3.WebUserControl1" %>
<asp:Label ID="Label1" runat="server" Text="Hi am on a control"></asp:Label>

Open in new window

Public Class _Default
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not Page.IsPostBack Then
            Dim uc As New WebUserControl1
        End If
    End Sub

End Class

Open in new window

<%@ Page Title="Home Page" Language="vb" MasterPageFile="~/Site.Master" AutoEventWireup="false"
    CodeBehind="Default.aspx.vb" Inherits="WebApplication3._Default" %>

<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">

    <asp:Panel ID="Panel1" runat="server">

Open in new window


Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 5 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros