Upload1" runat="server" Width="400px" />
</td>
<td style="width: 100px">
<asp:Button ID="bt_upload" runat="server" OnClick="bt_upload_Click" Text="上传"
OnClientClick="return Check_FileType()"/></td>
</tr>
<tr>
<td style="width: 104px; height: 21px;">
<asp:Label ID="lb_info" runat="server" ForeColor="Red" Width="183px"></asp:Label></td>
<td style="width: 100px; height: 21px">
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
说明:点击上传时先触发客户端事件
Check_FileType;
4.服务器端检查上传文件类型(以上传图片为例)
效果图:
后台代码:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void bt_upload_Click(object sender, EventArgs e)
{
try
{
if (FileUpload1.PostedFile.FileName == "")
{
this.lb_info.Text =