Hi,
I have created a set of generic UserControls that i plan to use in various websites.
From the article http://msdn.microsoft.com/en-us/library/aa479318.aspx it looks like it is possible to compile the user-controls into a re-usable custom controls and add them as dll-libraries in my other web-sites.
But when i try to test a user-control by the design mentioned in the article, I get null-ponter exceptions.
Have anyone done this before, and is this a design-pattern that is normal to use, or should I re-write the code to ServerControls?
Web.config:
<pages>
<controls>
<add tagPrefix="uc" namespace="TestUserControls" assembly="TestUserControls"/>
</controls>
</pages>
Default.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default2.aspx.cs" Inherits="TestUserControls.Default2" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<uc:TestControl id="test2" runat="server" />
</div>
</form>
</body>
</html>
TestControl.ascx
<%@ Control Language="C#"
AutoEventWireup="true" CodeBehind="TestControl.ascx.cs"
Inherits="TestUserControls.TestControl" %>
<asp:Label ID="lblTest" runat="server" />
TestControl.ascx.cs
namespace TestUserControls
{
public partial class TestControl : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
lblTest.Text = "Test"; <-- Get null-ponter exception here
}
}
}