Working with controls inside of a Server table.

S

Scott Kelley

I have a control inside of an asp:Table control. Once I place it in
there, I can't seem to edit it any more (Double click to add events,
drag to reposition, etc...). If I use an HTML table, no problem. Is
there any way around this. I have tried grid layout as well as flow
layout. Sample of the code.

<asp:Table id="Table1" runat="server" Width="512px" Height="344px"
BorderColor="Black" BorderStyle="Solid" BorderWidth="1px"
GridLines="Both">
<asp:TableRow>
<asp:TableCell>
<asp:TextBox id="TextBox1" runat="server"></asp:TextBox>
</asp:TableCell>
<asp:TableCell></asp:TableCell>
</asp:TableRow>
</asp:Table>
 
J

Jeffrey Palermo [MCP]

Scott,
You've discovered the Page's control hierarchy. I invite you to turn
Trace on to look at the control hierarchy for yourself. When you put server
controls on a page, the designer will automatically generate event handlers
for you. The textbox here is not a child of the page but a child of another
server control (Table), which is a child of the page. The table is in the
Page's Controls collection, but the textbox is in the Table's Controls
collection. To get to the TextBox, consider the following sample code:

//In Page_Load or Init
TextBox txt = (TextBox)tbl.FindControl("txt");
Trace.Write(txt.ID);
txt.TextChanged+=new EventHandler(txt_TextChanged);
private void txt_TextChanged(object sender, EventArgs e)
{
Trace.Warn("Text changed");
}

So since the textbox is inside another server control, it is not a direct
child of the Page, so the Page designer will not act on it.

Best regards,
Jeffrey Palermo
 
S

Scott Kelley

May I assume then that there is no way around this? Controls that are
contained in other controls are just not workable in Visual
Studio.NET. I remember working in VB 5 and 6 and even if a control
was contained in another control, there was still a way to work with
it (click to create functions, drag and position, etc...). Makes me
rethink designing things this way if I can't work with controls in the
GUI editor. Thanks for the info.

Scott.
 

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

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top