Issue:
I have a markup like this (only the 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-behind:
namespace MainSolution.CONTROLTEMPLATES.Kunde
public partial class RTDeluxe : UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
linkUl.InnerHtml = string.Empty;
}
}
I can access the ul
inside the code-behind and get no compilation error. But, when I debug the code I get a NullReferenceException
because linkUl
is NULL.
First I thought that the namespaces are the reason. But, after several tries, I'm sure that they're correct. The FileLocation
seems to be correct and the controltemplates
folder of my iis has a "Kunde" folder with the corresponding ascx files in it.
I have other .ascx files with the same structure -> they're working like a charm.
Question:
Are there any other reasons than the namespace for such behaviour? Do you have any hints where 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:
Ok, I will try to answer all your questions. Thanks for your time and feedback!
- I have restarted Visual Studio -> The Problem persists.
- I also have cleaned up the solution and deployed a new one. -> The problem persists.
- When I debug and check the control hierachy I can see that the label is NOT there.
- When I change the ID the compiler throws an error in the code-behind (which is right). If i change the ID there two I get the same behavoiur as before.
- I also restarted my IIS and the whole pc -> No changes.
- I have added a
Name
attribute to the linkul-definition -> No changes. - When I try to use
FindControl
it returns NULL. - The target-framework is .NET 3.5
- The linkul is NOT inside a repeater or any other controls.
- Removing/changing the web.config does also not lead to a solution.
- Adding
EnsureChildControls
before accessing thelinkUl
doesnt change anything. - Moving the code into Page_PreRender does also not work.
I will try out your suggestions not listed here and add them soon.
Edit3:
Here the full 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 some additional info I found out:
When I change something in the markup, like adding plain html text it's NOT recognized by or shown in the browser. When i do something like this:
Label label1 = new Label();
label1.Text = "hugo lives!";
Controls.Add(label1);
It is shown. It seems like in visual studio everything is fine... But "live" at the server the code-behind speaks to some weird different markup...