使用单个按钮单击文件上传 [英] fileupload using single button click

查看:81
本文介绍了使用单个按钮单击文件上传的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尊敬的先生,

使用单键单击即可上传文件.

我在隐藏字段中放置了一个文本框,fileupload html控件和一个按钮控件.
如果我按下按钮,则自动打开文件对话框并选择文件,然后文本框中突然显示文件路径.
但是这些引用仅适用于IE.但不能在Mozilla Firebox中使用.


请帮帮我!..


.aspx文件:
------------

Dear sir,

fileupload using single button click.

i put one textbox,fileupload html control in hidden field and one button control.
if i press the button ,automatically openfiledialog open and choose the file, then suddenly file path display in textbox.
but these cituation working only IE. but not working in Mozilla firebox.


please help me!..


.aspx file:
------------

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="opendialog2.aspx.cs" Inherits="opendialog2" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript" language="javascript">
        function getFile()
        {
        debugger;
            document.getElementById("File1").click();
            var file1="";
            if(document.getElementById("TextBox1").value=="")
                file1 = document.getElementById("File1").value;
            else
                file1 = document.getElementById("TextBox1").value +
            "\r\n" + document.getElementById("File1").value;
            document.getElementById("TextBox1").value = file1;
        }
</script>
</head>
<pre lang="xml"><body>
    <form id="form1" runat="server">
    <div>
    <table align="center" ><tr align="center" ><td  align="center" valign="middle" >
       <asp:TextBox ID="TextBox1" runat="server" Height="29px" Width="323px"></asp:TextBox>
    </td>
    <td>
       <asp:Button ID="Button1" runat="server"  OnClick="Button1_Click"    Text="open"  />
       <td>
        <input id="File1&quo<code><big><small><big>><<a href=""></a><a href=""></a>[<a href="" target="_blank"></a>]<a href=""></a></big></small></big></code>t; type="file" style=
 "width:119px;left:238px;position:absolute;top:41px;visibility:hidden;"
/></td>
    </td>
    </tr></table>

    </div>
    </form>
</body>

</html>





.cs(c sharp)文件:
-------------------





.cs(c sharp) file:
-------------------

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class opendialog2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Button1.Attributes.Add("OnClick", "getFile()");
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
    }
}

推荐答案

这永远都行不通,您永远也不能访问文件上载控件,因为它可能被用来作恶.
This should never work, you should never have access to the file upload control, as it can be used for evil.


这篇关于使用单个按钮单击文件上传的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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