上传文件到服务器自动在asp.net网站更新面板内 [英] Upload a file to server automatically inside a update panel in asp.net website

查看:205
本文介绍了上传文件到服务器自动在asp.net网站更新面板内的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有更新面板中的文件上传,并且上传文件到服务器的上传按钮。是否可以将文件上传不点击上传按钮? 我想尽快删除上传按钮,上传文件的文件是从用户的机器上选择即可。或者说,有4秒的定时器,然后调用 upload_click 来检查文件上传有一个文件或没有。我怎样才能做到这一点没有更新面板内的按钮?

 < ASP:的UpdatePanel ID =UP_DDL=服务器的UpdateMode =始终ChildrenAsTriggers =真>
    <&的ContentTemplate GT;
        < ASP:文件上传ID =FileUpload1=服务器/>
        < ASP:按钮的ID =上传的OnClick =Upload_Click=服务器文本=上传/>
    < /&的ContentTemplate GT;
    <&触发器GT;
        < ASP:PostBackTrigger控件ID =上传/>
    < /触发器>
< / ASP:的UpdatePanel>保护无效Upload_Click(对象发件人,EventArgs的发送)
{
    如果(FileUpload1.HasFile)
    {
        //创建路径保存文件
        字符串文件名= Path.Combine(使用Server.Mappath(〜/批量上载),FileUpload1.FileName);
        //将文件保存到本地路径
        FileUpload1.SaveAs(文件名);
    }
}


解决方案

我相信你可以使用任何的HTML输入文件元素的事件来火了一个完整的回发,这是所​​有你为了自动上传的文件所需要的。

谷歌,至少在标准接口上,使用一些Flash插件来完成你想要什么。

有可能是一些其他的jQuery插件提供此功能的开箱即用。 这其中,例如,似乎做了。

I have a file upload inside the update panel, and an upload button that uploads the file to the server. Is it possible to upload the file without clicking the upload button? I want to remove the upload button and upload the file as soon as the file is selected from the user's machine. Or, have a 4 second timer, then call the upload_click to check if the fileupload has a file or not. How can I do it without a button inside update panel?

<asp:UpdatePanel ID="UP_DDL" runat="server" UpdateMode="Always" ChildrenAsTriggers="true">
    <ContentTemplate> 
        <asp:FileUpload ID="FileUpload1" runat="server" />
        <asp:Button ID="Upload" OnClick="Upload_Click" runat="server" Text="Upload" />
    </ContentTemplate>
    <Triggers>
        <asp:PostBackTrigger ControlID="Upload"/>
    </Triggers>
</asp:UpdatePanel>

protected void Upload_Click(object sender, EventArgs e)
{
    if (FileUpload1.HasFile)
    {
        //create the path to save the file to     
        string fileName = Path.Combine(Server.MapPath("~/Bulk Upload"), FileUpload1.FileName);
        //save the file to our local path  
        FileUpload1.SaveAs(fileName);
    }
}

解决方案

I am sure you can use any of the events on the HTML INPUT File element to fire up a full post back, which is all you need in order to upload the file automatically.

Google, at least on the standard interface, uses some sort of Flash plugin to accomplish what you want.

There might be some other jQuery plugins that provide this functionality out of the box. This one, for example, seems to do it.

这篇关于上传文件到服务器自动在asp.net网站更新面板内的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆