How do u wire up events to controls in a custom template control???

C

Chris Newby

I have a very basic custom control that exposes an ITemplate property and
everything seems pretty straight forward so far.

But, when I put other server controls intro the template section of my
custom control in the ASPX page:

<cc1:MyCustomControl id=MyCustomControl1 runat="server">
<MyTemplate>
<asp:listbox id=ListBox1 runat="server"
AutoPostBack="True"></asp:listbox>
</MyTemplate>
</cc1:MyCustomControl>

.... how am I suppose to programatically access ListBox1 from the ASPX's code
behind?

I realize I can "DOM Craw" my way to it ... but it seems like there must be
a better way. For example, if I double click the ListBox control from the
designer, Visual Studio goes about automatically generating the code to tie
a SelectedIndexChanged event handler to ListBox1. However, the code it
generates fails at runtime because the code behind class doesn't seem to
know anything about an actual instance of ListBox1, even though one
certainly exists way down the Control Tree within MyCustomControl1.

I would like consumers of my control to be able to deal with the controls
they decide to put into the templated sections as if they were putting them
anywhere else in the ASPX document. What do I need to do from here?

TIA from a very tired programmer//
 
G

Guest

Hi Chris
in ur code imports the namespace and than declare this control
protected mycontrol ...................etc
Hope this help :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top