NullReferenceException With Different Register Directive

Discussion in 'ASP .Net Web Controls' started by Marvin Massih, Mar 23, 2006.

  1. 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

    --
    http://groenndemon.de/blog
    Marvin Massih, Mar 23, 2006
    #1
    1. Advertising

  2. Marvin Massih

    Ward Bekker Guest

    Ward Bekker, Mar 23, 2006
    #2
    1. Advertising

  3. 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

    --
    http://groenndemon.de/blog
    Marvin Massih, Mar 23, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sergey Polyakov
    Replies:
    0
    Views:
    389
    Sergey Polyakov
    May 24, 2004
  2. Dan
    Replies:
    3
    Views:
    596
    =?Utf-8?B?RGFu?=
    Jun 14, 2004
  3. =?Utf-8?B?UGF1bCBQcmV3ZXR0?=

    Null Reference Exception on @Register Directive

    =?Utf-8?B?UGF1bCBQcmV3ZXR0?=, Sep 27, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    306
    =?Utf-8?B?UGF1bCBQcmV3ZXR0?=
    Sep 27, 2006
  4. Tim Burkart
    Replies:
    0
    Views:
    771
    Tim Burkart
    Feb 10, 2008
  5. Marvin Massih

    NullReferenceException With Different Register Directive

    Marvin Massih, Mar 23, 2006, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    125
    Marvin Massih
    Mar 23, 2006
Loading...

Share This Page