在ASP.NET中的AjaxFileUpload UploadComplete事件上重新加载GridView或Repeater
Hi在AjaxFileUpload UploadComplete事件之后是否仍有更新(Gridview或Repeater数据)。我想做的是使用AjaxFileUpload上传多张图片,一旦上传文件,它就会将这些图片显示到GridView或Repeater控件中 除非触发按钮单击事件,否则无法执行此操作在ASP.NET中的AjaxFileUpload UploadComplete事件上重新加载GridView或Repeater,asp.net,ajax,file-upload,Asp.net,Ajax,File Upload,Hi在AjaxFileUpload UploadComplete事件之后是否仍有更新(Gridview或Repeater数据)。我想做的是使用AjaxFileUpload上传多张图片,一旦上传文件,它就会将这些图片显示到GridView或Repeater控件中 除非触发按钮单击事件,否则无法执行此操作 有什么想法吗?将隐藏按钮放到表单上,并将此函数附加到extender的onClient LoadComplete事件处理程序 <asp:Button runat="server" ID="H
有什么想法吗?将隐藏按钮放到表单上,并将此函数附加到extender的
onClient LoadComplete
事件处理程序
<asp:Button runat="server" ID="HiddenButton" OnClick="RefreshGridView" style="display:none;" />
function uploadComplete(sender, args) {
for (var index = 0; index < sender._filesInQueue.length; ++index) {
if (!sender._filesInQueue[index]._isUploaded) {
return;
}
}
__doPostBack("<%= HiddenButton.UniqueID %>", "");
})
函数上载完成(发送方,参数){
对于(var index=0;index
然后,单击此按钮刷新您的GridView。此代码检查上载的文件,使用文件信息创建电子邮件,使用链接向文件的目标用户发送电子邮件。它还将所有信息存储到数据库中。上载页面上有一个gridview,其中列出了已上载的所有文件。它会在加载文件后更新。我想你可以从中得到你所需要的
Partial Class upload_Default
Inherits System.Web.UI.Page
Protected Sub UploadButton2_Click(sender As Object, e As EventArgs)
Dim fileGuid As String
fileGuid = Guid.NewGuid.ToString
If AsyncFileUpload1.HasFile Then
If AsyncFileUpload1.FileContent.Length < 20971500 Then
Try
Dim fileSizeB As Integer = AsyncFileUpload1.PostedFile.ContentLength
Dim fileSize = fileSizeB / 1024
Dim filename As String = Path.GetFileName(AsyncFileUpload1.FileName)
Dim fileNameTwo As String = Trim(fileGuid) + Trim(filename)
Dim ExistPdfFilenamOPO As String
ExistPdfFilenamOPO = Server.MapPath("~/uploads/files/") & filename
If File.Exists(ExistPdfFilenamOPO) Then
Label2.Text = "File is already there"
Else
Dim saveDir As String = "\Uploads\files\"
Dim appPath As String = Request.PhysicalApplicationPath
Dim savePath As String = appPath + saveDir + _
Server.HtmlEncode(AsyncFileUpload1.FileName)
AsyncFileUpload1.SaveAs(savePath)
UploadStatusLabel2.Text = "Upload status: File uploaded."
Label2.Text = ""
' Email
Dim sr As New StreamReader(appPath & "EmailTemplates/FileUpload.htm")
Dim FName As String = TextBoxFName.Text
Dim LName As String = TextBoxLName.Text
Dim Email As String = TextBoxEmail.Text
Dim fullPath As String
fullPath = "https://website.com/uploads/default.aspx?fileGuid=" + fileGuid
Dim message As New MailMessage()
message.IsBodyHtml = True
message.From = New MailAddress("Your email")
message.[To].Add(New MailAddress(Email))
message.Subject = "The file you requested from SRTR"
message.Body = sr.ReadToEnd()
sr.Close()
message.Body = message.Body.Replace("<%FName%>", FName)
message.Body = message.Body.Replace("<%LName%>", LName)
message.Body = message.Body.Replace("<%Email%>", Email)
message.Body = message.Body.Replace("<%FileName%>", filename)
message.Body = message.Body.Replace("<%VerificationUrl%>", fullPath)
Dim client As New SmtpClient()
client.Send(message)
'Insert in to t_UploadFiles
Dim datenow As Date = System.DateTime.Now()
Dim ExDate As Date = datenow.AddDays(15)
Dim Downloaded As Boolean = False
Dim connectionString As String = ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString
Dim updateSql As String = "INSERT t_UploadFiles (FileGuid, FileName, FileSize, FName, LName, Email, UploadDate, ExDate, Downloaded) SELECT @FileGuid, @FileName, @FileSize, @FName, @LName, @Email, @UploadDate, @ExDate, @Downloaded"
Using myConnection As New SqlConnection(connectionString)
myConnection.Open()
Dim myCommand As New SqlCommand(updateSql, myConnection)
myCommand.Parameters.AddWithValue("@FileGuid", fileGuid.Trim())
myCommand.Parameters.AddWithValue("@FileName", filename.Trim())
myCommand.Parameters.AddWithValue("@FileSize", fileSize)
myCommand.Parameters.AddWithValue("@FName", FName.Trim())
myCommand.Parameters.AddWithValue("@LName", LName.Trim())
myCommand.Parameters.AddWithValue("@Email", Email)
myCommand.Parameters.AddWithValue("@UploadDate", datenow)
myCommand.Parameters.AddWithValue("@ExDate", ExDate)
myCommand.Parameters.AddWithValue("@Downloaded", Downloaded)
myCommand.ExecuteNonQuery()
myConnection.Close()
End Using
articleListXX.DataBind()
End If
Catch ex As Exception
UploadStatusLabel2.Text = "Upload status: The file could not be uploaded.<br/>The following error occured: " + ex.Message
End Try
Else
UploadStatusLabel2.Text = "File is too large."
End If
Else
UploadStatusLabel2.Text = "You did not specify a file to upload."
End If
End Sub
End Class
部分类上载\u默认值
继承System.Web.UI.Page
受保护的子上载按钮2\u单击(发件人作为对象,e作为事件参数)
将文件GUID设置为字符串
fileGuid=Guid.NewGuid.ToString
如果AsyncFileUpload1.HasFile,则
如果AsyncFileUpload1.FileContent.Length<20971500,则
尝试
Dim fileSizeB As Integer=AsyncFileUpload1.PostedFile.ContentLength
Dim fileSize=fileSizeB/1024
Dim文件名为String=Path.GetFileName(AsyncFileUpload1.filename)
Dim filename2作为String=Trim(fileGuid)+Trim(filename)
Dim EXISTDFFILENAMOPO作为字符串
ExistPdfFilenamOPO=Server.MapPath(“~/uploads/files/”)&filename
如果File.ExistPdfFilenamOPO存在,则
Label2.Text=“文件已经存在”
其他的
Dim saveDir As String=“\Uploads\files\”
Dim appPath作为字符串=Request.PhysicalApplicationPath
将保存路径设置为字符串=appPath+saveDir+_
Server.HtmlEncode(AsyncFileUpload1.FileName)
AsyncFileUpload1.SaveAs(保存路径)
UploadStatusLabel2.Text=“上载状态:文件已上载。”
Label2.Text=“”
“电子邮件
Dim sr作为新的StreamReader(appPath和“EmailTemplates/FileUpload.htm”)
Dim FName As String=TextBoxFName.Text
Dim LName As String=TextBoxLName.Text
Dim Email As String=TextBoxEmail.Text
将完整路径设置为字符串
完整路径=”https://website.com/uploads/default.aspx?fileGuid=“+fileGuid
将消息变暗为新邮件消息()
message.IsBodyHtml=True
message.From=新邮件地址(“您的电子邮件”)
邮件。[收件人]。添加(新邮件地址(电子邮件))
message.Subject=“您从SRTR请求的文件”
message.Body=sr.ReadToEnd()
高级关闭()
message.Body=message.Body.Replace(“,FName)
message.Body=message.Body.Replace(“,LName”)
message.Body=message.Body.Replace(“,电子邮件”)
message.Body=message.Body.Replace(“,文件名)
message.Body=message.Body.Replace(“,完整路径)
作为新SmtpClient()的Dim客户端
客户端发送(消息)
'插入到t_上载文件
Dim datenow As Date=System.DateTime.Now()
Dim ExDate As Date=datenow.AddDays(15)
作为布尔值下载的Dim=False
Dim connectionString As String=ConfigurationManager.connectionString(“connectionString”).connectionString
Dim updateSql As String=“插入上传文件(文件GUID、文件名、文件大小、FName、LName、电子邮件、上传日期、ExDate、下载)选择@FileGuid、@FileName、@FileSize、@FName、@LName、@Email、@UploadDate、@ExDate、@Downloaded”
将myConnection用作新的SqlConnection(connectionString)
myConnection.Open()
将myCommand设置为新的SqlCommand(更新SQL、myConnection)
myCommand.Parameters.AddWithValue(“@FileGuid”,FileGuid.Trim())
myCommand.Parameters.AddWithValue(“@FileName”,FileName.Trim())
myCommand.Parameters.AddWithValue(“@FileSize”,FileSize)
myCommand.Parameters.AddWithValue(“@FName”,FName.Trim())
myCommand.Parameters.AddWithValue(“@LName”,LName.Trim())
myCommand.Parameters.AddWithValue(“@Email”,Email)
myCommand.Parameters.AddWithValue(“@UploadDate”,datenow)
myCommand.Parameters.AddWithValue(“@ExDate”,ExDate)
myCommand.Parameters.AddWithValue(“@Downloaded”,已下载)
myCommand.ExecuteOnQuery()
myConnection.Close()
终端使用
articleListXX.DataBind()
如果结束
特例
UploadStatusLabel2.Text=“上载状态:无法上载文件。
发生以下错误:“+ex.Message”
结束尝试
其他的
UploadStatusLabel2.Text=“文件太大。”
如果结束
其他的
UploadStatusLabel2.Text=“您没有指定要上载的文件。”
如果结束
端接头
末级
好的,伙计们,谢谢你们的贡献,很抱歉做出了这样的贡献
<script type="text/javascript">
function showUploadedPic()
{
__doPostBack('btnAdd', null);
}
</script>
<cc1:AjaxFileUpload ID="AjaxFileUpload1" runat="server" OnUploadComplete="AjaxFileUpload1_UploadComplete" ThrobberID="myThrobber" MaximumNumberOfFiles="10" AllowedFileTypes="jpg,jpeg" OnClientUploadComplete="showUploadedPic" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<asp:Image ID="Image1" runat="server" ImageUrl="<%# Container.DataItem %>" height="100"/>
</ItemTemplate>
</asp:Repeater>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnAdd" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
protected void btnAdd_Click(object sender, EventArgs e)
{
populatePic();
}
protected void AjaxFileUpload1_UploadComplete(object sender, AjaxControlToolkit.AjaxFileUploadEventArgs e)
{
string filePath = Server.MapPath("~/files/") + e.FileName;
AjaxFileUpload1.SaveAs(filePath);
createThumbnail();
}
<asp:Button runat="server" ID="HiddenButtonFileUpload"
<ajax:AjaxFileUpload ID="AjaxFileUpload11" runat="server"
MaximumNumberOfFiles="3" AllowedFileTypes="txt,xls,xlsx,doc,docx,pdf"
Width="400px"
OnUploadComplete="OnUploadComplete"
OnClientUploadStart="UploadStart" OnClientUploadCompleteAll="UploadComplete"
ClearFileListAfterUpload="true" />
function UploadComplete() {
unblock();
__doPostBack("<%= HiddenButtonFileUpload.UniqueID %>", "");
}
Code Behind :
protected void RefreshGridView(object sender, EventArgs e)
{
BindForm(); // refresh your gridview
}