我在我的网络表单中使用了 3 个文件上传控件,在这里我给出了它的截图。
这是我的 aspx.cs 文件代码,
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BusinessLayer;
using System.IO;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
namespace EventManagerApp.SuperAdmin
{
public partial class Settings : System.Web.UI.Page
{
public string FilePath;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
General_SettingsBL gb = new General_SettingsBL();
gb.Privacy_Policies = System.IO.Path.GetExtension(fuprivacypolicies.FileName);
gb.Privacy_Policies = System.IO.Path.GetExtension(fuprivacypolicies.FileName);
gb.Refund_Policies = System.IO.Path.GetExtension(furefundpolicies.FileName);
gb.Terms = System.IO.Path.GetExtension(futerms.FileName);
gb.Trial_Period = decimal.Parse(txttrailperoid.Text);
gb.Insert();
lblmsg.Visible = true;
lblmsg.Text = "Records Inserted Successfully";
}
protected void btnCancel_Click(object sender, EventArgs e)
{
}
protected void deleterefundpolicies(object sender, EventArgs e)
{
furefundpolicies.ID = null;
protected void deleteprivacypolicies(object sender, EventArgs e)
{
fuprivacypolicies.ID = null;
// fuprivacypolicies = new FileUpload();
}
protected void deleteterms(object sender, EventArgs e)
{
futerms.ID = null;
// futerms = new FileUpload();
}
}
}
我将此代码用于 .aspx 文件,
<%@ Page Title="" Language="C#" MasterPageFile="~/SuperAdmin/EventManager_SuperAdmin.Master" AutoEventWireup="false" CodeBehind="Settings.aspx.cs" Inherits="EventManagerApp.SuperAdmin.Settings" %>
<%@ Register TagPrefix="asp" Namespace="AjaxControlToolkit" Assembly="AjaxControlToolkit" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<div class="container">
<div class="row">
<h3>
Settings</h3>
<hr>
</div>
<div class="row">
<div class="col-md-6">
<form class="form-horizontal" role="form">
<div class="form-group">
<label for="inputEmail1" class="col-md-4 control-label">
Refund Policies: </label>
<div class="col-md-6">
<asp:FileUpload ID="furefundpolicies" runat="server" />
</div>
<div class="col-md-6">
<asp:Button ID="btnrefunfpolicy" runat="server" Text="DELETE" class="btn btn-default" OnClick="deleterefundpolicies" />
</div>
</div>
<div class="form-group">
<label for="inputEmail1" class="col-md-4 control-label">
Privacy Policies</label>
<div class="col-md-6">
<asp:FileUpload ID="fuprivacypolicies" runat="server" />
</div>
<div class="col-md-6">
<asp:Button ID="btnprivacypolicy" runat="server" Text="DELETE" class="btn btn-default" OnClick="deleteprivacypolicies" />
</div>
</div>
<div class="form-group">
<label for="inputEmail1" class="col-md-4 control-label">
Terms</label>
<div class="col-md-6">
<asp:FileUpload ID="futerms" runat="server" />
</div>
<div class="col-md-6">
<asp:Button ID="btnterms" runat="server" Text="DELETE" class="btn btn-default" OnClick="deleteterms" />
</div>
</div>
<div class="form-group">
<label for="inputEmail1" class="col-md-4 control-label">
Trial Period</label>
<div class="col-md-6">
<asp:TextBox ID="txttrailperoid" runat="server" class="form-control"></asp:TextBox>
<%-- <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txttrailperoid"
Display="Dynamic" ErrorMessage="Please Enter Value"></asp:RequiredFieldValidator>--%>
</div>
</div>
<div class="col-md-10">
<asp:Label ID="lblmsg" runat="server" Visible="false" class="alert alert-success form-group"></asp:Label>
</div>
<div class="form-group">
<label for="inputEmail1" class="col-md-4 control-label">
</label>
<div class="col-md-6">
<asp:Button ID="btnSubmit" runat="server" Text="SAVE" class="btn btn-default" OnClick="btnSubmit_Click" />
<asp:Button ID="btnCancel" runat="server" Text="CANCEL" CausesValidation="false"
class="btn btn-default" OnClick="btnCancel_Click" />
</div>
</div>
</form>
</div>
</div>
</div>
</asp:Content>
在我的屏幕截图中,我描述了我的问题,我只想删除一个上传的文件。