在UpdatePanel'pnlUpdate'中找不到ID为'btnUpload'的控件的触发器

时间:2013-08-19 04:27:06

标签: c# asp.net file-upload updatepanel

我有一个用户控件,我想放在更新面板中,我的代码看起来像这样

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="QuestionControl.ascx.cs"
Inherits="ProcessFramework.QuestionControl" %>
<%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %>
<asp:UpdatePanel ID="pnlUpdate" runat="server">
<Triggers>
<asp:PostBackTrigger ControlID="btnUpload" />
</Triggers>
<ContentTemplate>
    <asp:DataList ID="QuestionList" runat="server" OnItemDataBound="QuestionList_ItemDataBound"
        OnEditCommand="LinkButton1_EditCommand">
        <ItemTemplate>
            <div class="QuestionObject">
                <asp:HiddenField ID="QuestionID" runat="server" Value='<%# Eval("QuestionID") %>' />
                <span class="QuestionsLabel">
                    <h2>
                        <asp:Label ID="QuestionTextLabel" runat="server" Text='<%# Eval("QuestionText") %>'></asp:Label></h2>
                </span>
                <asp:Panel ID="LinkPanel" runat="server" Visible='<%# Eval("HasLink") %>' CssClass="QuestionsLink">
                    <asp:HyperLink runat="server" ID="QuestionLink" Text='<%# Eval("LinkText") %>' Target="_blank"
                        NavigateUrl='<%# Eval("LinkURI") %>'></asp:HyperLink>
                </asp:Panel>
                <br />
                <asp:Panel ID="ResponseInputPanel" runat="server" Visible="false" CssClass="QuestionsText">
                    <asp:TextBox runat="server" Text='<%# Eval("Response") %>' TextMode="MultiLine" CssClass="TextArea"
                        ID="QuestionResponseTextBox">
                    </asp:TextBox><asp:HtmlEditorExtender ID="HtmlEditorExtender1" TargetControlID="QuestionResponseTextBox"
                        runat="server" EnableSanitization="false" DisplaySourceTab="true">
                        <Toolbar>
                            <asp:Undo />
                            <asp:Redo />
                            <asp:Bold />
                            <asp:Italic />
                            <asp:Underline />
                            <asp:StrikeThrough />
                            <asp:Subscript />
                            <asp:Superscript />
                            <asp:JustifyLeft />
                            <asp:JustifyCenter />
                            <asp:JustifyRight />
                            <asp:JustifyFull />
                            <asp:InsertOrderedList />
                            <asp:InsertUnorderedList />
                            <asp:CreateLink />
                            <asp:UnLink />
                            <asp:RemoveFormat />
                            <asp:SelectAll />
                            <asp:UnSelect />
                            <asp:Delete />
                            <asp:BackgroundColorSelector />
                            <asp:ForeColorSelector />
                            <asp:FontNameSelector />
                            <asp:FontSizeSelector />
                            <asp:Indent />
                            <asp:Outdent />
                            <asp:InsertHorizontalRule />
                            <asp:HorizontalSeparator />
                            <asp:Cut />
                            <asp:Copy />
                            <asp:Paste />
                        </Toolbar>
                    </asp:HtmlEditorExtender>
                    <div class="QuestionActions">
                        <asp:LinkButton ID="lnkClear" runat="server" Text="Clear" OnCommand="lnkClearA_OnCommand"
                            CommandArgument='<%# Container.ItemIndex %>' Visible="false">
                        </asp:LinkButton>
                        <label>
                            |</label>
                        <asp:LinkButton ID="LinkClearAll" runat="server" Text="Preview" OnCommand="lnkClearAllResponse_OnCommand"
                            CommandArgument='<%# Container.ItemIndex %>' Visible="false">
                        </asp:LinkButton>
                        <asp:Panel ID="AttachmentPanel" runat="server" Visible='<%# Eval("HasAttachment") %>'
                            CssClass="QuestionsAttachment">
                            <asp:Panel ID="AttachmentPanelUploadSection" runat="server" Visible='<%# (bool.Parse(Eval("IsAttachmentExist").ToString()) == false) %>'>
                                <asp:Literal ID="AttachFileLabel" runat="server" Text="Attach file (Max 10MB):" /><asp:FileUpload
                                    ID="FileUpload1" runat="server" CssClass="button" />
                                <asp:Button ID="btnUpload" runat="server" Text="Upload" CssClass="button" OnCommand="btnUpload_OnCommand"
                                    CommandArgument='<%# Container.ItemIndex %>' />
                            </asp:Panel>
                            <asp:Panel ID="AttachmentPanelFileInfoSection" runat="server" Visible='<%# Eval("IsAttachmentExist") %>'>
                                Attachment:
                                <asp:Literal ID="AttachementFileName" runat="server" Text='<%# Eval("AttachmentURI") %>'
                                    Visible="true" />
                                <asp:LinkButton ID="RemoveAttachment" runat="server" CommandArgument='<%# Container.ItemIndex %>'
                                    CssClass="imagelink" OnCommand="lnkRemoveAttachment_OnCommand" ToolTip="Remove"
                                    Height="16px">                       
                                </asp:LinkButton>
                            </asp:Panel>
                        </asp:Panel>
                    </div>
                </asp:Panel>
                <asp:Panel ID="ResponseLabelPanel" runat="server" Visible="true">
                    <div class="QuestionsResponse">
                        <asp:Literal ID="ResponseLiteral" runat="server" Text='<%# Eval("Response") %>' />
                    </div>
                    <asp:LinkButton ID="LinkEditResponse" runat="server" Text="Edit" OnCommand="lnkEditResponse_OnCommand"
                        CommandArgument='<%# Container.ItemIndex %>'>
                    </asp:LinkButton>
                    <asp:Image ID="AttachmentIcon" runat="server" Visible='<%# (bool.Parse(Eval("IsAttachmentExist").ToString()) == true) %>'
                        ImageUrl="~/Content/Images/attachment.png" Width="14" Height="14" Style="float: right;
                        position: relative" />
                    <asp:LinkButton ID="LinkButton1" ToolTip="Download Attachment" runat="server" CommandName="Edit"
                        CssClass="linkbutton" Visible='<%# (bool.Parse(Eval("IsAttachmentExist").ToString()) == true) %>'
                        CommandArgument='<%# Eval("AttachmentURI") %>' Text='<%# Eval("AttachmentURI") %>' />
                </asp:Panel>
            </div>
        </ItemTemplate>
        <SelectedItemStyle BackColor="#CC3333" Font-Bold="True" ForeColor="White" />
        <SeparatorTemplate>
            <hr style="margin-top: 5px" />
        </SeparatorTemplate>
    </asp:DataList>
    <asp:HiddenField ID="ObjID" runat="server" />
    <br />
    <table style="width: 200px;" align="right">
        <tr>
            <td>
                <asp:Button ID="btnCancel" runat="server" CssClass="btn" OnClick="btnCancel_Click"
                    Text="Cancel" Visible="false" />
            </td>
            <td>
                <asp:Button ID="btnSubmit" runat="server" CssClass="btn" OnClick="btnSubmit_Click"
                    Text="Save" Visible="false" />
            </td>
        </tr>
    </table>
    <br />
    <br />
    <hr />
    <webdiyer:AspNetPager ID="AspNetPager1" runat="server" Width="100%" HorizontalAlign="center"
        OnPageChanged="AspNetPager1_PageChanged" PageSize="1" ShowPageIndexBox="Never"
        AlwaysShowFirstLastPageNumber="true" PagingButtonSpacing="5" UrlPaging="false"
        AlwaysShow="false" CssClass="paginator" CurrentPageButtonClass="cpb">
    </webdiyer:AspNetPager>
</ContentTemplate>

由于我将文件上传控件放在更新面板中,我还设置了回发触发器,控件控件ID为点击我上传数据的按钮ID的id。这个问题是否发生导致我将按钮放在控件内?任何人都可以帮我解决这个问题吗?

1 个答案:

答案 0 :(得分:1)

由于我的用户控件在DataList控件中,我在ItemCreated事件上执行了以下操作,并且功能正常工作

protected void QuestionList_ItemCreated(Object sender, DataListItemEventArgs e)
    {
        Control uploadButton =  e.Item.FindControl("btnUpload");
        Control DownloadLinkButton = e.Item.FindControl("LinkButton1");                                
        if (uploadButton != null)
        {
            ScriptManager mgr = ScriptManager.GetCurrent(this.Page);                
            mgr.RegisterPostBackControl(uploadButton);
            mgr.RegisterPostBackControl(DownloadLinkButton);                
        }
    }