FindControl works without UpdatePanel, breaks with UpdatePanel

Last post 05-21-2007 5:51 PM by otint. 1 replies.

Sort Posts:

  • FindControl works without UpdatePanel, breaks with UpdatePanel

    02-08-2007, 12:19 PM
    • Loading...
    • headchem
    • Joined on 02-08-2007, 4:24 PM
    • Elon, NC
    • Posts 30

    I have read these forums for quite some time, but this is my first post.  I apologize if the answer is to be found here, but I have come up empty-handed in my searches

    The scenario:

    I have an UpdatePanel that contains within it a GridView.  The GridView is ItemTemplate'ed where I control all of the layout of data per row.  Within each row is another UpdatePanel that contains a LinkButton.  When I remove this second UpdatePanel, my FindControl() successfully finds the LinkButton I am trying to access.  However, when the second UpdatePanel is present, the exact same FindControl() returns null.  Below is the source:

    <asp:UpdatePanel ID="UpdatePanelFacstaff" runat="server">
            
    <ContentTemplate>
                Faculty / Staff Connections
    <br />
                <
    asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="false"
                    OnPageIndexChanging
    ="gridView_PageIndexChanging" PageSize="1" OnRowCreated="GridView_RowCreated">
                    
    <Columns>
                        
    <asp:TemplateField>
                            
    <ItemTemplate>
                                
    <img alt='' src='../images/profile/thumb/<%# Eval("user_guid") %>.jpg' /><a href='../profile/Default.aspx?guid=<%# Eval("user_guid") %>'><%# Eval("display_name") %></a>
                                - 
    <a href='../messages/Default.aspx?to_guid=<%# Eval("user_guid") %>'>send a message</a>
                                
    <asp:Literal ID="LiteralConnected" runat="server" Text="You are connected" Visible='<%# Eval("connected") %>' />
                                <
    asp:UpdatePanel ID="UpdatePanelAddConnection" runat="server">
                                    
    <ContentTemplate>
                                
    <asp:LinkButton ID="LinkButtonAddConnection" runat="server" Text="Add Connection" Visible='<%# !Boolean.Parse(Eval("connected").ToString()) %>'
                                    CommandArgument
    ='<%# Eval("user_guid").ToString() %>' OnCommand="AddFriend" />
                                <
    asp:Panel ID="PanelConnectionRequested" runat="server" Visible="false">
                                    You have requested a connection with
                                    
    <%# Eval("display_name") %>
                                    .
    </asp:Panel>
                                
    </ContentTemplate>
                                
    </asp:UpdatePanel>
                            
    </ItemTemplate>
                        
    </asp:TemplateField>
                    
    </Columns>
                
    </asp:GridView>
            
    </ContentTemplate>
        
    </asp:UpdatePanel>
     
     
    And in the code-behind where "addButton" returns null:
     
     
    protected void GridView_RowCreated(Object sender, GridViewRowEventArgs e)
        {

            
    if (e.Row.RowType == DataControlRowType.DataRow)
            {
                
    // Retrieve the LinkButton control from the row
                //UpdatePanel rowUpdatePanel = (UpdatePanel)e.Row.FindControl("UpdatePanelAddConnection");
                
    LinkButton addButton (LinkButton)e.Row.FindControl("LinkButtonAddConnection");

                
    // Set the LinkButton's CommandName property with the row's index.
                
    addButton.CommandName e.Row.RowIndex.ToString();
            
    }
        }
     
     
    Thank you for your help with this! 
    Filed under: ,
  • Re: FindControl works without UpdatePanel, breaks with UpdatePanel

    05-21-2007, 5:51 PM
    • Loading...
    • otint
    • Joined on 05-19-2007, 10:38 PM
    • Posts 1

    Hi, wondering if you ever got an answer to this, having the same problem....

Page 1 of 1 (2 items)
Microsoft Communities
Page view counter