我有一个带有fileupload控件的problam 我有一个手风琴,在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"));
}
}
}
答案 0 :(得分:0)
通过执行FindControl,您在顶级容器中搜索并且FindControl不是递归的。如果你想找到上传控件,你需要从直接父母搜索,这似乎是Accordion1。
FileUpload fu = Accordion1.FindControl("FileUpload1") as FileUpload;