以下代码是实现上传文件的,我不想用标签控件来显示上传的结果(红色代码部分),而是想用弹出一个小窗口来显示上传的结果。如何在 *.aspx.cs 页面中编写 JavaScript 脚本???
protected void Button1_Click(object sender, EventArgs e)
{
if (IsPostBack)
{
Boolean fileOK = false;
String path = Server.MapPath("~/file/");
if (FileUpload1.HasFile)
{
String fileExtension =
System.IO.Path.GetExtension(FileUpload1.FileName).ToLower();
String[] allowedExtensions =
{ ".xls", ".doc"}; //过滤Word和Excel文件
for (int i = 0; i < allowedExtensions.Length; i++)
{
if (fileExtension == allowedExtensions[i])
{
fileOK = true;
}
}
}
if (fileOK)
{
try
{
FileUpload1.PostedFile.SaveAs(path
+ FileUpload1.FileName);
Label1.Text = "File uploaded!";
}
catch (Exception ex)
{
Label1.Text = "File could not be uploaded.";
}
}
else
{
Label1.Text = "Cannot accept files of this type.";
}
}
}