0
我有一個fileUpload控件和裏面的Button裏面UpdatePanel和用戶需要上傳文件使用fileUpload控件和button.How添加回發觸發器的按鈕,以便所選文件通過fileupload獲取上傳到服務器。設置回車觸發器裏面的datalist裏面updatepanel
<asp:UpdatePanel runat="server" ID="UpdatePanel">
<ContentTemplate>
<asp:DataList ID="dlComments" runat="server" Width="100%"
onitemcommand="dlComments_ItemCommand" DataKeyField="CommentID"
onitemdatabound="dlComments_ItemDataBound" >
<ItemTemplate>
<asp:Label ID="lblSnNo" runat="server" class="label-small-grey" Text='<%#Eval("CommentNumber") %>' ></asp:Label>
<label style="font-size:12px; font-style:normal"><%#Eval("CommentText") %></label>
<textarea runat="server" id="txtaCommentText" style="resize:none;" rows="3" cols="3" class="form-control" placeholder="Your Comments Here"></textarea><Br>
<asp:FileUpload ID="fileUploadReply" multiple="true" runat="server" class="" /></p><br>
<asp:Button ID="btnPostReplyComment" CommandName="PostReplyComment" class="btn btn-primary" runat="server" Text="Post" />
</ItemTemplate>
</asp:DataList>
</ContentTemplate>
<Trigger>
</Triggers>
</asp:UpdatePanel>
在代碼隱藏,
protected void dlComments_ItemCommand(object source, DataListCommandEventArgs e)
{
if (e.CommandName == "PostReplyComment")
{
FileUpload fileUploadReply = (FileUpload)e.Item.FindControl("fileUploadReply");
functionTOStoreCommetns();
string filename = Path.GetFileName(fileUploadReply.FileName);
fileUploadReply.SaveAs(Server.MapPath("~/") + filename);
}
}
的文件遭到上傳,如果它的數據列表加入PostBackTrigger到的UpdatePanel 不在請幫忙添加後回到觸發了插嘴
我做到了b ut拋出一個錯誤:在UpdatePanel'UpdatePanel'中找不到觸發器'ID fileUploadReply' – 2014-09-11 08:18:41
您控制着控件或DataList行或DataList本身的可見性嗎?如果控件未呈現,則不會被找到。 – navigator 2014-09-11 09:54:37