Event of button is not fired when i browse any fil

2019-09-20 06:14发布

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条回答
不美不萌又怎样
2楼-- · 2019-09-20 06:18

please try after including this in your web.config file

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

查看更多
爱情/是我丢掉的垃圾
3楼-- · 2019-09-20 06:18

In aspx file:

<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>

In code behind:

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!";
}

You can also refer to this link:

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

查看更多
登录 后发表回答