C# 点击按钮上传图片
我必须上传图像与图像按钮点击。 我尝试了以下代码C# 点击按钮上传图片,c#,javascript,image,file-upload,C#,Javascript,Image,File Upload,我必须上传图像与图像按钮点击。 我尝试了以下代码 <head runat="server"> <title></title> <script> function browse() { document.getElementById('<%= FileUpload1.ClientID %>').click(); } </script> </head> <body> &
<head runat="server">
<title></title>
<script>
function browse() {
document.getElementById('<%= FileUpload1.ClientID %>').click();
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:toolkitscriptmanager ID="ToolkitScriptManager1" runat="server">
</asp:toolkitscriptmanager>
<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:ImageButton ID="ImageButton1" runat="server" OnClientClick="browse();"
ImageUrl="logo.gif" />
</div>
</form>
</body>
函数浏览(){
document.getElementById(“”)。单击();
}
在“图像”按钮上单击“浏览”窗口打开。但当我点击图片并打开它时,图片路径在上传控件文本框中是不可见的,就像我们通常使用没有imagebutton的上传控件一样。这意味着upload control.Hasfile为false
有人能帮我吗
提前感谢当您使用文件上传器浏览图像时,文本框中会自动显示路径 不需要额外的眉毛或图像按钮 默认情况下,“浏览”按钮是给定的 您可以在以下链接中学习带图形表示的文件上传器教程: 如果要保存图像,请在代码中使用此函数:
protected void btnUploadClick(object sender, EventArgs e)
{
HttpPostedFile file = Request.Files["myFile"];
if (file != null && file.ContentLength )
{
string fname = Path.GetFileName(file.FileName);
file.SaveAs(Server.MapPath(Path.Combine("~/App_Data/", fname)));
}
}
当您使用文件上传器浏览图像时,文本框中会自动显示路径 不需要额外的眉毛或图像按钮 默认情况下,“浏览”按钮是给定的 您可以在以下链接中学习带图形表示的文件上传器教程: 如果要保存图像,请在代码中使用此函数:
protected void btnUploadClick(object sender, EventArgs e)
{
HttpPostedFile file = Request.Files["myFile"];
if (file != null && file.ContentLength )
{
string fname = Path.GetFileName(file.FileName);
file.SaveAs(Server.MapPath(Path.Combine("~/App_Data/", fname)));
}
}
对图像按钮使用以下代码:
OnClientClick=“browse();return false;”“为图像按钮使用以下代码:
OnClientClick=“browse();return false;”我需要添加一个图像,并希望浏览窗口打开。我确实这么做了,但现在还没开始uploaded@SandraDsouzaplz在代码中有上述功能,如果你想保存图像,我需要添加一个图像,我想打开浏览窗口。我确实这么做了,但现在还没开始uploaded@SandraDsouza如果要保存该图像,请在代码中使用plz的上述功能