以下是示例
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!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 CheckFileType()
{
var objButton = document.getElementById("savebtn"); //上传按钮
var objFileUpload=document.getElementById('FileUpload1');//FileUpload
var objMSG=document.getElementById('msg');//显示提示信息用的DIV
var FileName=new String(objFileUpload.value);//文件名
var extension=new String (FileName.substring(FileName.lastIndexOf(".")+1,FileName.length));//文件扩展名
if(extension=="jpg"||extension=="JPG")//你可以添加扩展名
{
objButton.disabled=false;//启用上传按钮
objMSG.innerHTML="";
}
else
{
objButton.disabled=true;//禁用上传按钮
objMSG.innerHTML="请选择正确的文件文件";
}
}
</script>
<style type="text/css">
.style1
{
width: 103px;
}
#Text1
{
width: 277px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<table style="width: 100%; ">
<tr>
<td class="style1">
<label id="title" >标题</label>
</td
<td>
<input id="Text1" runat="server" type="text" />
<asp:Button ID="savebtn0" runat="server" Text="修改" onclick="savebtn_Click" />
</td>
</tr>
<tr>
<td class="style1">
<label id="Label1" >修改图片路径</label>
</td>
<td>
<input id="Radio1" type="radio" >使用默认路径</>
</td>
<td>
</td>
</tr>
<tr >
<td class= "style1">
</td>
<td><input id="Radio2" type="radio" >上传图片</>
<asp:FileUpload ID="FileUpload1" runat="server" onChange="javascript:CheckFileType();" />
</td>
<td>
<div id="msg"></div>
<asp:Button ID="savebtn" runat="server" Text="保存" onclick="savebtn_Click" />
</td>
</tr>
</table>
</div>
</form>
</body>
</html>