【问题标题】:Event of button is not fired when i browse any file through fileupload control and upload it..connection time out error当我通过文件上传控件浏览任何文件并上传它时,不会触发按钮事件。连接超时错误
【发布时间】:2013-08-07 08:17:58
【问题描述】:
你好, 我的应用程序中有文件上传控件和上传按钮 asp:FileUpload ID="FileUpload1" runat="server" Width="250px" /> asp:Button runat="server" ID="btn_upload" Text="Upload" onclick="btn_upload_Click" 我已将其包含在 .aspx 文件中 当我使用此控件浏览任何文件并单击上传按钮时 我收到连接超时错误。 .这种情况仅适用于文件上传控件,但如果我浏览任何文件并单击上传按钮,则不会出现此错误, 上传按钮(btn_upload_Click)的点击事件被触发,但在浏览上传按钮的任何文件点击事件后,文件上传控件未触发。 .为什么会出现这个问题..请帮助

【问题讨论】:

  • 感谢您的回答。实际上这个问题是因为浏览器问题而出现的

标签: asp.net events button file-upload onclick


【解决方案1】:

请在您的 web.config 文件中包含此内容后尝试

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

【讨论】:

    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 2017-10-12
      • 2012-06-04
      • 1970-01-01
      • 1970-01-01
      • 2017-09-06
      • 1970-01-01
      • 1970-01-01
      • 2019-09-22
      • 2018-11-20
      相关资源
      最近更新 更多