Quantcast
Channel: Web Forms
Viewing all articles
Browse latest Browse all 23244

UserControl doesn't show

$
0
0

I am trying to create a simple user control that contains an ImageButton and a Label but the problem is the ImageBox and Label don't appear to have been properly set - they just show the default don't exist values..

Here is the ascx file:

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="WebUserControl1.ascx.cs" Inherits="WebApplication7.WebUserControl1" %>
<div>
<asp:ImageButton ID="ImageButton1" runat="server" AlternateText="BadImage" />
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</div>

I am trying programmatically add a new user control object to my windows form:

 protected void Page_Load(object sender, EventArgs e)
        {

            String srcName = "This-Is-Our-Time";
            ImageButton imageButton = new ImageButton();
        //    imageButton.ImageUrl = "~/Data/" + srcName + ".jpg";
            imageButton.ImageUrl = "~/Data/This-Is-Our-Time.jpg";

            imageButton.Height = Unit.Pixel(150);
            imageButton.Width = Unit.Pixel(200);
            imageButton.Style.Add("padding", "5px");

            Label label1 = new Label();
            label1.Text = "Great Movie";

           // WebUserControl1 webControl1 = new WebUserControl1();

            WebUserControl1 webControl1 = (WebUserControl1)LoadControl("~/WebUserControl1.ascx");  

            webControl1.Imager = imageButton;
            webControl1.Labeler = label1;

            imageButton.Click += new ImageClickEventHandler(imageButton_Click);

            Panel1.Controls.Add(webControl1);

In the ascx.cs file for the control I have this:

 public partial class WebUserControl1 : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            
        }
        public ImageButton Imager
        {
            get { return ImageButton1; }
            set { ImageButton1 = value; }
        }

        public Label Labeler
        {
            get { return Label1; }
            set { Label1 = value; }
        }
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
        }
    }

Any help appreciated and thanks in advance.


Viewing all articles
Browse latest Browse all 23244

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>