M
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
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