我已经烧了三天试图让这个工作并实现我在SO和其他网站上找到的每个建议。没有快乐。这是一个非常常见的问题,我认为它会更容易解决。显然我错过了一些东西。
我正试图让代码隐藏“看到”这个asp:Button,但它不会这样做。
我将以当前的形式浏览页面和代码隐藏。在过去的三天里,他们经历了一系列的变化。
<%@ 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> 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> 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>
以下是代码隐藏中的调用:
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);
无论我对该调用(或前面的代码)做了什么,myButton始终为null。
我错过了一些非常明显的东西吗?