<td></td>
<td colspan="4"> <asp:Image ID="Image1" runat="server" Width="94%" Height="100PX"/></td>
<td style="width: 5px"></td>
</tr>
<tr height="25">
<td></td>
<td>图片上传:</td>
<td colspan="3"><asp:FileUpload ID="FileUpload1" runat="server" Width="90%" TabIndex="66" />
<script language="javascript" type="text/javascript">
var showPic = function(obj){
var fileURLSplit = obj.value.split(".");
var fileExt=fileURLSplit[fileURLSplit.length-1].toLowerCase();
if(fileExt=="jpg" || fileExt=="gif" ||fileExt=="bmp")
{
var img = document.getElementById("Image1");
img.src = "file:///" + obj.value;
img.onerror = function(){
alert("请选择一个图片文件!");
}
}
else
{
obj.value = " ";
alert("请选择jpg、gif或bmp图片文件");
}
}
</script>
后台代码:
FileUpload1.Attributes["onchange"] = "showPic(this)";