首页 文章

当我通过fileupload控件浏览任何文件并上传它时,不会触发按钮事件 . 连接超时错误

提问于
浏览
-1
Hi,
I have file upload control and upload button in my application

   asp:FileUpload ID="FileUpload1" runat="server" Width="250px" />

    asp:Button runat="server" ID="btn_upload" Text="Upload"
 onclick="btn_upload_Click" 

i have included it in .aspx file
when i browse any file using this control and click on upload button
 i got the connection timeout error.
.this case is only with fileupload control,but if i dint browse any file and click on upload button then this error is not coming,
click event of upload button(btn_upload_Click) gets fired but with Fileupload control after browsing any file click event of upload button not firing.
.why this problem occurs..plz help

2 回答

  • 0

    请在web.config文件中包含此项后尝试

    <system.web> <httpRuntime executionTimeout="999999" maxRequestLength="2097151" /> </system.web>

  • 0

    在aspx文件中:

    <asp:FileUpload ID="FileUpload1" runat="server" />
             <asp:Button ID="Button1" runat="server" Text="Upload" 
                onclick="Button1_Click" />
                <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
    

    代码背后:

    protected void Button1_Click(object sender, EventArgs e)
    {
        string filename = Path.GetFileName(FileUpload1.FileName);
        FileUpload1.SaveAs(Server.MapPath("~/") + filename);
        Label1.Text = "Upload status: File uploaded!";
    }
    

    您也可以参考以下链接:

    http://asp.net-tutorials.com/controls/file-upload-control/

相关问题