Home All Groups Group Topic Archive Search About

NullReferenceException With Different Register Directive

Author
23 Mar 2006 10:21 AM
Marvin Massih
Hello,

I have written a user control using .NET 1.1 and have had some trouble.
But to make sure it's not a problem with my code I have had the designer
(VS.NET 2003) create a new user control for me and include that in a new
web form.

The user control only contains a Repeater:

------ SNIP ------
<asp:Repeater id="Repeater1" runat="server">
<ItemTemplate>
<asp:Label Runat="server">
<%# Container.DataItem.ToString() %>
</asp:Label>
</ItemTemplate>
</asp:Repeater>
------ SNAP ------

It is supposed to be filled in the code-behind like this:

------ SNIP ------
protected Repeater Repeater1;

private void Page_Load(object sender, EventArgs e)
{
     ArrayList a = new ArrayList();
     a.Add("Hello");
     a.Add("World");

     Repeater1.DataSource = a;
     Repeater1.DataBind();
}
------ SNAP ------

I then dragged this user control onto a new web form and everything
works as a charm.

Obviously this is because the designer creates a Register directive like
this:

------ SNIP ------
<%@ Register TagPrefix="uc1" TagName="Foobar" Src="Foobar.ascx" %>
------ SNAP ------

If I change this to

------ SNIP ------
<%@ Register Tagprefix="XY" Namespace="My.Namespace" Assembly="XYWeb" %>
------ SNAP ------

The control is still loaded, but Repeater1 is null in Page_Load, which
causes a NullReferenceException to be thrown.

Any help will be highly appreciated.

-Marvin


Author
23 Mar 2006 10:25 AM
Ward Bekker
Hi Marvin,

Did you try to add the control from the XYWeb to the toolbox and drag it
to the page? Maybe a different register tag is added that might work better.

--
Ward Bekker
"Asp.Net Discussions for the Professional Developer"
http://www.dotnettaxi.com

"Free .Net 2.0 C# to/from VB.Net Code Converter"
http://www.dotnettaxi.com/Tools/Converter.aspx
Author
23 Mar 2006 11:08 AM
Marvin Massih
Hi Ward,

Ward Bekker wrote:
> Did you try to add the control from the XYWeb to the toolbox and drag it
> to the page? Maybe a different register tag is added that might work
> better.

Tried now, VS.NET says "XYWeb does not contain any elements that can be
placed in the toolbox" or something like that (I have the German version).

But the Foobar control is compiled into the assembly, at least it's part
of the project.

-Marvin