我有一个基本页面,我要在其中添加一个基于
Bulk Uploader
在c-sharpcorner.com,控件位于jquery fasted div中,基于
yesdegisn
批量上载程序有两个用于两个按钮的服务器端事件处理程序——添加和删除。单击这些按钮后,淡入淡出将消失,您将返回到基本页——如果用户需要添加更多文件,则这是不可取的。添加到列表框的文件数组列表被维护,但我必须单击“淡入”链接(LinkButton id=“lnkDocumentUpload”)才能再次显示此窗口。
我还需要将控件发布到uploadpost.aspx,它也不起作用。单击上载按钮(
<asp:Button ID="btnUpload" runat="server" />
)具有上面描述的相同行为——淡入淡出消失,保留数据,不发布。我已经用
<form id="frmUpload" action="~/UploadPost.aspx">
...
<asp:Button ID="btnUpload" runat="server" Text="Upload"/>
</form>
链接按钮通过激活淡入jquery
$("#lnkDocumentUpload").click(function() {
centerPopup();
loadPopup();
});
MyUploader标记:
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="MyUploader.ascx.cs" Inherits="Controls.MyUploader" %>
<form id="frmUpload" action="~/UploadPost.aspx">
<table>
<tr>
<td style="width: 163px">
<span style="font-size: 10pt; font-family: Verdana"><strong>
Select file to upload:</strong></span></td>
<td style="width: 324px">
<asp:FileUpload ID="fUpload" runat="server" /> <asp:Button ID="btnAdd" runat="server" Text="Add"
OnClick="btnAdd_Click" /></td>
</tr>
<tr>
<td style="width: 163px">
</td>
<td style="width: 324px">
<asp:ListBox ID="lstFiles" runat="server" Width="324px"></asp:ListBox>
</td>
</tr>
<tr>
<td style="width: 163px">
</td>
<td style="width: 324px">
<asp:Button ID="btnRemove" runat="server" Text="Remove" OnClick="btnRemove_Click" />
<asp:Button ID="btnUpload" runat="server" Text="Upload"/></td>
</tr>
<tr>
<td colspan="2">
<asp:Label ID="lblMessage" runat="server" Font-Names="Verdana" Font-Size="Small"
ForeColor="Red"></asp:Label></td>
</tr>
</table>
MyUploader代码隐藏:
public partial class MyUploader : System.Web.UI.UserControl
{
protected static ArrayList arrFiles = new ArrayList(); // has to be static since Adding and then reusing
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnAdd_Click(object sender, EventArgs e)
{
try
{
if (Page.IsPostBack)
{
arrFiles.Add(fUpload);
lstFiles.Items.Add(fUpload.PostedFile.FileName);
}
}
catch (Exception ex)
{
lblMessage.Text = "An error has occured while adding file" + ex.Message;
}
}
protected void btnRemove_Click(object sender, EventArgs e)
{
if (lstFiles.Items.Count != 0)
{
arrFiles.Remove(fUpload);
lstFiles.Items.Remove(lstFiles.SelectedItem.Text);
}
}
}