我有一个文件上传控件的问题,我有一个手风琴,在 ContentTemplate 里面我有一个文件上传控件,当提交发送按钮时,我试图找到该控件,但总是让它为空。
<asp:Accordion ID="Accordion1" runat="server" AutoSize="None" FramesPerSecond="40"
SelectedIndex="-1" TransitionDuration="100" FadeTransitions="true" RequireOpenedPane="false"
SuppressHeaderPostbacks="true" ContentCssClass="accordionContent" HeaderCssClass="accordionHeader"
HeaderSelectedCssClass="accordionHeaderSelected"
OnItemCommand="Accordion1_ItemCommand"
onitemdatabound="Accordion1_ItemDataBound">
<HeaderTemplate>
<%#DataBinder.Eval(Container.DataItem, "order_id")%>
<asp:Label ID="lblOrderID" runat="server" Text='<%#Eval("description")%>'></asp:Label>
</HeaderTemplate>
<ContentTemplate>
<asp:Label ID="lblNotes" runat="server" Text='<%#Eval("notes")%>'></asp:Label>
<asp:Label ID="lbltext" runat="server" Text='להגשת מועמדות למשרה זו צרף קו"ח'></asp:Label>
<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:Button ID="btnSend" runat="server" Text="שלח" CommandName="send" />
</ContentTemplate>
</asp:Accordion>
protected void Accordion1_ItemCommand(object sender, CommandEventArgs e)
{
if (e.CommandName == "send")
{
FileUpload fu = new FileUpload();
fu = (FileUpload) FindControl("FileUpload1");
if (fu.HasFile)
{
SmtpClient client = new SmtpClient();
MailAddress from = new MailAddress("", "יש לך הודעה חדשה", System.Text.Encoding.UTF8);
MailAddress to = new MailAddress("");
MailMessage message = new MailMessage(from, to);
message.Body = "";
//Attachment data = new Attachment(FileUpload.
//message.Attachments.Add(FindControl("fu"));
}
}
}