Controls in my Template are not available to the code-behind
Messages   Related Types
This message was discovered on ASPFriends.com 'aspngcontrolscs' list.


Bryan Costanich
All,

I have created a templated control as shown here:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/htm
l/cpconcustomizingcontrolswithtemplates.asp

I can use the control in my aspx page as follows:

<Controls:Control1 runat="server" id="test1">
    <FirstTemplate>
        <asp:Label Runat="server" ID="lblTest1">Test</asp:Label>
    </FirstTemplate>
</Controls:Control1>

This works just fine, but when I try to access it in the code-behind as
follows:

    protected Label lblTest1;
    ...

    lblTest1.Text = "test test tes 2";            

I get an error because the control = null. Has anyone else had this
problem? know of a solution???

Reply to this message...
 
    
Remas Wojciechowski
Bryan,

to my knowledge, in order to access controls in a template, you need to use
the FindControl method of the host control.

hth
Remas
http://www.aspalliance.com/remas

----- Original Message -----
From: "Bryan Costanich" <Click here to reveal e-mail address>
To: "aspngcontrolscs" <Click here to reveal e-mail address>
Sent: Thursday, August 01, 2002 10:11 PM
Subject: [aspngcontrolscs] Controls in my Template are not available to the
code-behind

[Original message clipped]

Reply to this message...
 
 




Ad
MBR BootFX
Best-of-breed application framework for .NET projects, developed by Matthew Baxter-Reynolds and MBR IT
 
 Copyright © Matthew Baxter-Reynolds 2001-2008. '.NET 247 Software Development Services' is a trading style of MBR IT Solutions Ltd.
Contact Us - Terms of Use - Privacy Policy - www.dotnet247.com