Get Controls from Control Template ASP.NET

Hi All,

I have a very strange problem from my point of view.

I have created a Control with a Control Template. It only have one ControlTemplate which is Content.

I create a new instance with this code:

<mc:ContainerWindow runat="server" id="ContainerWindow1">
<Content>
<asp:DropDownList runat="server" id="DropDownList1"></asp:DropDownList>
</Content>
</mc:ContainerWindow>

Now I want to get the dropdownlist from codebehind.
I then try to debug and step into my method which return the control, this works fine and I get the object returned.
If I on the other hand try to debug and step over the method, I get a NullReferenceException.

The method is overiding FindControl and return FindControl on the datacontainer I use to instatiateIn.

My questions is now:
Why is there a difference between step into and step over?
How can I get the control from the ControlTemplate?

I have used this link: http://msdn.microsoft.com/en-us/library/aa478964.aspx I have just extended it a bit, please ask If you need some code supplied.

Thanks in advance.
munchimanAsked:
Who is Participating?
 
munchimanConnect With a Mentor Author Commented:
Never mind.

My problem was caused by missing call to EnsureChildControls
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.