|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
NullReferenceException With Different Register DirectiveI 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 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 Hi Ward,
Ward Bekker wrote: > Did you try to add the control from the XYWeb to the toolbox and drag it Tried now, VS.NET says "XYWeb does not contain any elements that can be > to the page? Maybe a different register tag is added that might work > better. 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
pop-up browser persist data back to parent page code-behind
How to add client script to a pushbutton in datagrid FileUpload - keep the filename How do change layout od SideBar in Wizard control? (ASP.NET 2.0) WebPart and WebPartZones Usage Navigation Menu Site Map Difficulties Access property and control of master page from a customized parent page class Alignment of webcontrols... CustomControl and body.onload AccessibleHeaderText property |
|||||||||||||||||||||||