0

I've burned three days trying to get this to work and implemented every suggestion I could find here on SO and other sites I Googled up. No joy. This is a VERY common problem and I'd think it would be easier to solve. Clearly I'm missing something.

I'm trying to get the code-behind to "see" this asp:Button, but it just won't do it.

I'll past the page and code-behind in their current form. They've gone through a mountain of changes over the last three days.

<%@ Page Title="" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeBehind="Shades.aspx.cs" Inherits="DisciplesWalk.Shades" %>
<asp:Content ID="Content1" ContentPlaceHolderID="Head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="Content" runat="server">
    <asp:Table ID="ShadesTable" runat="server" CellPadding="10">
        <asp:TableRow>
            <asp:TableCell>
                <asp:Image ImageAlign= "Middle" ID="ShadesBanner" runat="server" ImageUrl="~/Images/Banners/Shades.jpg" />
            </asp:TableCell>
        </asp:TableRow>
        <asp:TableRow>
            <asp:TableCell VerticalAlign="Top" Width="70%" HorizontalAlign="Left">
                <div style="overflow-y:scroll;height:450px"> 
                <asp:UpdatePanel ID="ShadesDisplayPanel" runat="server">
                    <ContentTemplate>
                        <asp:Repeater ID="ShadesRepeater" runat="server" OnItemDataBound="ShadesRepeater_OnItemDataBound" >
                            <ItemTemplate>
                                <br />
                                <asp:Label ID="ShadeDate" CssClass="ShadeDate" runat="server" Width="100%" Text='<%# Bind("ShadeDate", "{0:MM/dd/yyyy}") %>'></asp:Label>
                                <span class="notehead">
                                <asp:Label ID="ShadeTitle" CssClass="ShadeHeading" runat="server" Width="100%" Text='<%# Bind("ShadeTitle")%>'></asp:Label>
                                </span>
                                <br /><br />
                                <span>
                                <asp:Image ID="ShadeImageLeft" ImageUrl='<%# "~/Images/Shades/" + Eval("ShadeImage") %>' CssClass="shadeImageLeft" runat="server" />
                                <asp:Image ID="ShadeImageRight" ImageUrl='<%# "~/Images/Shades/" + Eval("ShadeImage") %>' CssClass="shadeImageRight" runat="server" />
                                <%# Eval("ShadeBody") %>
                                </span>
                                <br />
                                <AjaxToolkit:Accordion ID="ShadesAccordion" runat="server"
                                SelectedIndex="-1"
                                CssClass="accordion"
                                HeaderCssClass="accordionHeader"
                                HeaderSelectedCssClass="accordionHeaderSelected"
                                ContentCssClass="accordionContent"
                                AutoSize="None"
                                FadeTransitions="true"
                                TransitionDuration="250"
                                FramesPerSecond="40"
                                RequireOpenedPane="false"
                                SuppressHeaderPostbacks="true">
                                <Panes>
                                    <AjaxToolkit:AccordionPane runat="server" ID="AddCommentPane">
                                        <Header>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Add Comment</Header>
                                        <Content>
                                            <asp:Table ID="CommentsTable" runat="server" CellPadding="12" cellspacing="0" width="100%">
                                                <asp:TableRow ID="CommentsTableRow">
                                                    <asp:TableCell  HorizontalAlign="Left" ID="CommentsTableCell">
                                                        <br />
                                                        <asp:Label runat="server" ID="CommenterLabel" Text="Name:" Visible="True"></asp:Label>
                                                        <br />
                                                        <asp:TextBox ID="CommenterTextBox" runat="server" Width="25%"></asp:TextBox>
                                                        <br />
                                                        <asp:Label runat="server" ID="CommentLabel" Text="Your comment:" Visible="True"></asp:Label>
                                                        <br />
                                                        <asp:TextBox ID="CommentTextBox" runat="server" Width="90%"></asp:TextBox>
                                                        <br /><br />
                                                        <%-- This is the offending button.--%>
                                                        <asp:Button ID="SubmitCommentButton" runat="server" Text="Submit" />
                                                    </asp:TableCell>
                                                </asp:TableRow>
                                            </asp:Table>
                                        </Content>
                                    </AjaxToolkit:AccordionPane>
                                    <AjaxToolkit:AccordionPane runat="server" ID="ReadCommentsPane">
                                        <Header>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Read Comments</Header>
                                        <Content>
                                            <div style="overflow-y:scroll;height:450px"> 
                                            <asp:UpdatePanel ID="ShadeCommentDisplayPanel" runat="server">
                                                <ContentTemplate>
                                                    <asp:Repeater ID="ShadeCommentRepeater" runat="server">
                                                        <ItemTemplate>
                                                            <br />
                                                            <span>
                                                            <asp:Label ID="CommenterLabel" runat="server" Width="100%" Text='<%# Eval("Commenter")%>'></asp:Label>
                                                            </span>
                                                            <span>
                                                            <asp:Label ID="CommentBody" runat="server" Width="100%" Text='<%# Eval("Body")%>'></asp:Label>
                                                            </span>
                                                            <br />
                                                            <hr class="HRSeperator" />
                                                            <br /><br />
                                                        </ItemTemplate> 
                                                    </asp:Repeater>
                                                </ContentTemplate>
                                            </asp:UpdatePanel>
                                            </div>
                                        </Content>
                                    </AjaxToolkit:AccordionPane>
                                </Panes>
                            </AjaxToolkit:Accordion>
                            </ItemTemplate> 
                            <SeparatorTemplate>
                                <br />
                                <asp:Image ID="Image2" runat="server" ImageUrl="~/Images/separator.jpg" />
                                <br /><br />
                            </SeparatorTemplate>
                        </asp:Repeater>
                    </ContentTemplate>
                </asp:UpdatePanel>
                </div>
            </asp:TableCell>
        </asp:TableRow>
    </asp:Table>
    <asp:Table ID="NewShadeTable" runat="server" Width="100%" BorderWidth="0" GridLines="None" CellPadding="10">
        <asp:TableRow>
            <asp:TableCell VerticalAlign="Top">
                <asp:UpdatePanel ID="ShadeEntryPanel" runat="server">
                    <ContentTemplate>
                        <asp:Label ID="TitleLabel" runat="server" Text="Label">Enter Shade Title:</asp:Label> <br />
                        <asp:TextBox BackColor="#F2F2F2" ID="TitleTextBox" runat="server" Width="630"></asp:TextBox><br /><br />
                        <asp:Label ID="EnterShadeLabel" runat="server" Text="Label">Enter the Shade:</asp:Label><br />
                        <asp:TextBox BackColor="#F2F2F2" runat="server" TextMode="MultiLine" ID="ItemTextBox" Width="630" Rows="10" Height="140px"></asp:TextBox><br /><br />
                    </ContentTemplate>
                </asp:UpdatePanel>
            </asp:TableCell>
        </asp:TableRow>
        <asp:TableFooterRow>
            <asp:TableCell>
                <asp:Button ID="SubmitShadeButton" runat="server" Text="Submit" onclick="SubmitShade_Click" />
                <asp:Button ID="AddShadeButton" runat="server" Text="Add Shade" onclick="AddShade_Click" />
            </asp:TableCell>
        </asp:TableFooterRow>
    </asp:Table>
</asp:Content>

Here is the call being made in the code-behind:

protected void Page_Load(object sender, EventArgs e)
{
    Button myButton = new Button();
    myButton.Text = "Submit";
    myButton = (Button)this.ShadesRepeater.FindControl("ShadesAccordion").FindControl("AddCommentPane").FindControl("CommentsTable").FindControl("CommentsTableRow").FindControl("CommentsTableCell").FindControl("SubmitCommentButton");
    myButton.Click += new EventHandler(AddCommentButton_Click);

Regardless of what I do to that call (or the code up front), myButton is always null.

Am I missing something really obvious?

DJGray
  • 504
  • 8
  • 26
  • Have you determined if you are able to find the other controls in the chain? I notice that neither the the CommentsTable nor the Comments table row do not have the runat="server" attribute. – BGZ Aug 09 '13 at 21:23
  • BGZ, I can't see anything deeper than "ShadesRepeater." Per your suggestion, I'll add some runat statements and see if that helps. – DJGray Aug 09 '13 at 21:43
  • There actually was one on the table (see above) but I added one to both the table row and cell. No positive effect. Still throwing a null reference exception when the page loads. – DJGray Aug 09 '13 at 21:46

0 Answers0