Control Tree Recursion Using ASP.NET 2.0
page 3 of 5
by Tom Blanchard
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 30805/ 31

Creating Your WebForm

Ok, now add a new "Web Content Form", and select the "Master Page" that you just created. In your "Web Content Form", you should see the two "ContentPlaceHolder" controls from the "Master Page".

Within the 1st "ContentPlaceHolder" put a table that has a few rows with some link button controls like this:

Listing 3

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <table style="width:160px;vertical-align:top;">
        <tr>
            <td style="vertical-align:top">
                <asp:LinkButton ID="lb1" runat="server" OnClick="lbPanelShow_Click">lb1</asp:LinkButton>
            </td>
        </tr>
        <tr>
            <td>
             <asp:LinkButton ID="lb2" runat="server" OnClick="lbPanelShow_Click"> lb2 </asp:LinkButton>
            </td>
        </tr>
        <tr>
            <td>
            <asp:LinkButton ID="lb3" runat="server" OnClick="lbPanelShow_Click"> lb3</asp:LinkButton>
            </td>
        </tr>
        <tr>
            <td>
            <asp:LinkButton ID="lb4" runat="server" OnClick="lbPanelShow_Click"> lb4</asp:LinkButton>
            </td>
        </tr>
    </table>
</asp:Content>

We will work on the lbPanelShow_Click method when we get to the code behind.

Now we will add the section to the right where our content is going to go. We will add a panel for each of our link buttons:

Listing 4

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder2" runat="server">
<table style="width:640px">
    <tr>
        <td>
        <asp:Panel ID="pnl1" runat="server" Visible="false">
         Panel 1
        </asp:Panel>
         <asp:Panel ID="pnl2" runat="server" Visible="false">
          Panel 2       
         </asp:Panel>
         <asp:Panel ID="pnl3" runat="server" Visible="false">
          Panel 3
         </asp:Panel>
         <asp:Panel ID="pnl4" runat="server" Visible="false">
          Panel 4       
         </asp:Panel>
        </td>
    </tr>
</table>
</asp:Content>

Ok, now that we have our UI Together, we can go to the code behind.


View Entire Article

User Comments

Title: very useful   
Name: shubha
Date: 2008-09-12 7:09:52 AM
Comment:
this article was very useful for me. Actually i was struggling to find, how to find out the type of the control in a panel. Its a very simple solution to use 'is' operator. But i struggled a lot before finding this article..

thank u Tom Blanchard
Title: Very useful.   
Name: Dipal Bhavsar
Date: 2008-06-25 1:24:16 AM
Comment:
Hi, this is very useful to me...

Dipal Bhavsar
Title: check the link from the article in the first paragraph   
Name: TB
Date: 2008-02-19 1:22:29 PM
Comment:
It is just basically is an updated way to go through something similar in the 2.0 framework.
It is more of looping than recursing.
Title: Misleading   
Name: none
Date: 2008-02-19 12:48:02 PM
Comment:
This is nice and all, but there isn't anything recursive about it.
Title: Just what I was looking for!   
Name: Will Asrari
Date: 2007-06-14 11:48:50 PM
Comment:
Sweet. Thanks!
Title: Good Job   
Name: Tom Blanchard
Date: 2006-10-06 2:26:27 PM
Comment:
Excellent Job Rizwan! I didn't even go into HTMLControls, but glad it was easy for you to adapt.
Title: Rizwan Gulamhussein   
Name: Control Tree Recursion Using ASP.NET 2.0
Date: 2006-10-06 1:48:45 AM
Comment:
Sorry, by the way, I forgot to mention that your code as well as my own code snippet works.

Thanks.
Title: Control Tree Recursion Using ASP.NET 2.0   
Name: Rizwan Gulamhussein
Date: 2006-10-06 1:44:11 AM
Comment:
Great article Tom.

In my code, I have a single gridview that contains HTML radio buttons and HTML checkboxes. Although intellisense displays the name of the gridview, the debugger complained.

What I did was this:

GridView targetGrid = (GridView)FindControl("TargetSegmentGridView");

foreach (GridViewRow row in targetGrid.Rows)
{
etc.

Happy coding! :)
Title: Error in text   
Name: Tom Blanchard
Date: 2006-08-07 11:43:56 AM
Comment:
foreach(Control oCtl in ctl.Controls) {
Should read foreach(Control ctl1 in oCtl.Controls) {

Some of this was copied from actual code that I have used and some of the names were changed to protect the innocent, however, I apparently missed something.

My apologies.
Title: error   
Name: interesting
Date: 2006-08-07 11:25:12 AM
Comment:
when I run this, i get the following error

: CS0103: The name 'ctl' does not exist in the current context

Product Spotlight
Product Spotlight 





Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-04-18 7:01:11 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search