我正在使用 AJAX 控件工具包中的 asyncFileUpload 控件。我可以在后面的代码中对它进行类型转换并访问它,但它似乎没有抓取文件。这是它在页面中的嵌套方式:
<asp:LoginView ID="LoginView1" runat="server">
<AnonymousTemplate>
</AnonymousTemplate>
<LoggedInTemplate>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Repeater ID="rpt_items_loggedin" runat="server">
<ItemTemplate>
</ItemTemplate>
</asp:Repeater>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btn_addwish" EventName="click" />
</Triggers>
</asp:UpdatePanel>
<div class="wenslijst_preview">
<div class="fourfifth">
<table>
<tr>
<td>
<asp:Label ID="lbl_img" runat="server" Text="Upload een afbeelding:" AssociatedControlID="fu_img_upload"></asp:Label>
</td>
<td>
<asp:AsyncFileUpload ID="asfu_img" runat="server" UploaderStyle="Traditional" />
</td>
</tr>
</table>
</div>
<div class="fifth">
<asp:ImageButton ID="btn_addwish" runat="server" CssClass="icon_img"
ImageUrl="images/add.png" onclick="btn_addwish_Click"/>
</div>
</div>
</LoggedInTemplate>
</asp:LoginView>
这就是我在后面的代码中处理它的方式。当我调试时,我看到 AsyncFileUpload 控件没有获取任何数据:
protected void btn_addwish_Click(object sender, ImageClickEventArgs e)
{
AjaxControlToolkit.AsyncFileUpload f = new AjaxControlToolkit.AsyncFileUpload();
f = (AjaxControlToolkit.AsyncFileUpload)(this.LoginView1.FindControl("asfu_img"));
Label l = new Label();
l = (Label)(this.LoginView1.FindControl("lbl_img_feedback"));
string filePath = "";
if (f.HasFile)
{
try
{
string fileName = DateTime.UtcNow.Ticks + "_" + cId;
filePath = "images/userimg/" + fileName;
f.SaveAs(Server.MapPath(filePath));
l.Text = filePath;
}
catch (Exception ex)
{
l.Text = "Deze foto kon niet worden geuploaded. " + ex.Message;
}
}
}
如果您需要查看更多代码或信息,请告诉我!