I put some of my own web user controls in a separate project called "WebControls" and now I want to reuse them from another project
My Control consists of:
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="TestControl.ascx.cs" Inherits="WebControls.TestControl" %> <asp:Label ID="lblTest" runat="server" ></asp:Label> <asp:TextBox ID="textBox" runat="server" Width="" /> <asp:HiddenField ID="hiddenFieldId" runat="server" />
with code:
namespace WebControls { public partial class TestControl : System.Web.UI.UserControl { public Unit Width { get { return textBox.Width; } set { textBox.Width = value; } } public string SelectedId { get { return hiddenFieldId.Value; } set { hiddenFieldId.Value = value; } } public string SelectedText { get { return textBox.Text; } set { textBox.Text = value;} } protected void Page_Init(object sender, EventArgs e) { } protected void Page_Load(object sender, EventArgs e) { } } }
I am binding it to a webpage in another project:
<%@ Page Title="ToDo Serien" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="True" CodeBehind="RecurringToDos.aspx.cs" Inherits="TestAccess.RecurringToDos" %> <%@ Register Assembly="WebControls" Namespace="WebControls" TagPrefix="aci" %> <asp:Content runat="server" ID="FeaturedContent" ContentPlaceHolderID="FeaturedContent"> <section class="featured"> <div class="content-wrapper"> <hgroup class="title"> <h1><%: Title %>.</h1> <h2>Serienelement</h2> <aci:TestControl ID="aceRule" runat="server" Width="300" /> <asp:Button ID="btnSend" runat="server" OnClick="btnSend_Click" /> </hgroup> </div> ....
When I start the page now, it throws a reference null exception in the following line:
set { textBox.Width = value; }
becuase textBox = NULL
It seems that my control is not running properly. What am I doing wrong? How can i fix this?
Ephedra
source share