Question:
I have this markup (only important lines):
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="RTDeluxe.ascx.cs" Inherits="MainSolution.CONTROLTEMPLATES.Kunde.RTDeluxe" %> <ul id="linkUl" class="teaserLinksUL" runat="server"/>
The code:
namespace MainSolution.CONTROLTEMPLATES.Kunde public partial class RTDeluxe : UserControl { protected void Page_Load(object sender, EventArgs e) { linkUl.InnerHtml = string.Empty; } }
I can access ul inside the code and get a compilation error. But, when I debug the code, I get a NullReferenceException because linkUl is NULL.
At first, I thought that namespaces are the cause. But, after several attempts, I am sure that they are correct. FileLocation seems correct, and in the controltemplates folder of my iis there is a "Kunde" folder with the corresponding ascx files.
I have other .ascx files with the same structure -> they work like a charm.
Question:
Are there any other reasons besides the namespace for this behavior? Do you have any clues I can look at?
Edit:
The RTDeluxe.ascx.designer.cs file exists, the generated linkUl looks like this:
protected global::System.Web.UI.HtmlControls.HtmlGenericControl linkUl;
Edit2:
Well, I will try to answer all your questions. Thanks for your time and feedback!
- I restarted Visual Studio -> The problem persists.
- I also cleared the solution and deployed a new one. → The problem persists.
- When I debug and check the management hierarchy, I see that the label does NOT exist.
- When I change the identifier, the compiler throws an error in the code (this is correct). If I change the identifier, I get the same behavior as before.
- I also restarted my IIS and the whole PC -> No change.
- I added the
Name attribute to the definition of linkul -> No change. - When I try to use
FindControl , it returns NULL. - Target Structure - .NET 3.5
- Linkul is not inside the repeater or any other controls.
- Removing / modifying web.config also does not lead to a solution.
- Adding
EnsureChildControls before accessing linkUl will not change anything. - Moving code in Page_PreRender also does not work.
I will try your suggestions not listed here and add them soon.
Edit3:
Here's the complete markup:
<%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %> <%@ Assembly Name="Microsoft.Web.CommandUI, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="RTDeluxe.ascx.cs" Inherits="MainSolution.CONTROLTEMPLATES.Kunde.RTDeluxe" %> <ul id="linkUl" class="teaserLinksUL" runat="server"/>
* Edit4:
Ok, here are some additional information that I learned: When I change something in the markup, for example, by adding plain html text, it is NOT recognized or displayed in the browser. When I do something like this:
Label label1 = new Label(); label1.Text = "hugo lives!"; Controls.Add(label1);
Shown. It seems that everything is in order in the visual studio ... But "live" on the server, the code-code speaks of some strange different markup ...