asp.net FileUpLoad控件总是上传不了
<asp:FileUpload ID="FU" runat="server" /><asp:ImageButton ID="upload" runat="server" ImageUrl="~/ShowLove_image/upload.gif" CausesValidation="false"
Height="26px" Width="94px" onclick="upload_Click" />
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="FU"
ErrorMessage="必须是 jpg或者gif文件" ValidationExpression="^(([a-zA-Z]:)|(\\{2}\W+)\$?)(\\(\W[\W].*))+(.jpg|.Jpg|.gif|.Gif)$"></asp:RegularExpressionValidator>
后台:
protected void upload_Click(object sender, ImageClickEventArgs e)
{
if (FU.HasFile)
{
try
{
string serverPath = Server.MapPath("ShowLove_image");
string imgName = FU.FileName;
string NewPath = serverPath + "\\" + imgName;
FU.SaveAs(NewPath);
ScriptManager.RegisterStartupScript(UP, this.GetType(), "alert", "alert('上传成功!')", true);
detail.Text = "";
receiver.ImageUrl = "ShowLove_image/" + imgName;
detail.Text += " 路径 : " + FU.PostedFile.FileName + "\n" + " 大小 :" + FU.PostedFile.ContentLength / 1024 + "\n" + " 类型 :" + FU.PostedFile.ContentType;
}
catch
{
ScriptManager.RegisterStartupScript(UP, this.GetType(), "alert_1", "alert('上传失败!')", true);
}
}
else
{
ScriptManager.RegisterStartupScript(UP, this.GetType(), "alert_2", "alert('请选择图片!')", true);
}
}
总是通过不了验证控件,显示不是jpg文件,取下控件之后,通过不了hasfile方法,不知道什么原因导致了这个问题,麻烦各位了!!!