我正在使用Uploadify v2.1.4通过ASP.Net C# FM4.0上传图像。
在这个页面中,我还有其他控件,但我想要这样的功能,当我上传图像时,它应该自动刷新UpdatePanel1以显示已上传的图像
Default.aspx文件
<asp:UpdatePanel ID="UpdatePanel1" runat="server" >
<ContentTemplate>
<asp:DataList ID="DataList1" runat="server" DataSourceID="SqlDataSource1" RepeatDirection="Horizontal" >
<ItemTemplate>
<br /><img src='http://test.kashmirsouq.com/ImageUploads/<%# Eval("ImageID") %>' width="100px" height="100px" vspace="2" hspace="2" border="1" />
<br /><asp:LinkButton ID="lnkBtnDeleteImage" CommandArgument='<%# Eval("sno") %>' CommandName="Delete" runat="server">
Delete</asp:LinkButton>
<br />
</ItemTemplate>
</asp:DataList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:SQLConnectionString %>"
SelectCommand="SELECT [sno], [ImageID] FROM [User_Images]">
</asp:SqlDataSource>
</ContentTemplate>
</asp:UpdatePanel>页面示例在此处test.kashmirSouq.com
我正在调用FileUplaad.aspx文件来使用jQuery上传图片
<script type="text/javascript">
$(document).ready(function () {
$('#fuFiles').uploadify({
'uploader': 'Scripts/uploadify.swf',
'script': 'FileUploads.aspx',
'cancelImg': 'Scripts/cancel.png',
'auto': 'true',
'multi': 'true',
'fileExt': '*.jpg;*.gif;*.png',
'buttonText': 'Browse...',
'queueSizeLimit': 5,
'simUploadLimit': 2
});
});
</script>在FileUpload.aspx.cs文件中,我将文件保存在服务器和数据库中,我需要一种方法,以便可以从FileUpload.aspx.cs中的函数saveData()刷新updatepanel1
protected int saveData()
{
String strSql = "INSERT INTO HMS_User_Images(ImageID,UserID,ImageCreationDate) ";
strSql += " VALUES ('" + filename + "','123456789', '" + DateTime.Now + "')";
int result = DataProvider.intConnect_Select(strSql);
}因此,当我上传图像时,它应该刷新网格的部分页面更新。请给我一个使用C#的例子
请建议我如何做这个代码样本将非常感谢。
问候
发布于 2011-11-05 16:57:12
尝试使用Onupload complete event.So之后的响应来显示图像,当用户上传时,您将立即找到该图像。
脚本是这样的:
<script type="text/javascript">
$(window).load(
function () {
$("#fileInput1").uploadify({
'uploader': 'scripts/uploadify.swf',
'cancelImg': 'images/cancel.png',
'buttonText': 'Browse Files',
'script': 'Upload.aspx',
'folder': 'uploads',
'fileDesc': 'Image Files',
'fileExt': '*.jpg;*.jpeg;*.gif;*.png',
'queueSizeLimit': 9999,
'simUploadLimit': 2,
'sizeLimit': 4000000,
'multi': true,
'auto': true,
'onComplete': function (event, queueID, fileObj, response, data) {
$("#thumbnail").append(response)
},
'onError': function (event, ID, fileObj, errorObj) {
alert(errorObj.type + ' Error: ' + errorObj.info);
}
});
}
);
</script>这是处理程序:
<%@ WebHandler Language="VB" Class="UploadVB" %>
Imports System
Imports System.Web
Imports System.IO
Imports System.Drawing
Public Class UploadVB : Implements IHttpHandler
Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
Dim postedFile As HttpPostedFile = context.Request.Files("Filedata")
Dim savepath As String = ""
Dim tempPath As String = ""
tempPath = System.Configuration.ConfigurationManager.AppSettings("FolderPath")
savepath = context.Server.MapPath(tempPath)
Dim filename As String = postedFile.FileName
If Not Directory.Exists(savepath) Then
Directory.CreateDirectory(savepath)
End If
If Not Directory.Exists(savepath + "\thumbs") Then
Directory.CreateDirectory(savepath + "\thumbs")
End If
postedFile.SaveAs((savepath & "\") + filename)
Dim fullImage As System.Drawing.Image = New System.Drawing.Bitmap((savepath & "\") + filename)
Dim newWidth As Integer = 100
Dim newHeight As Integer = 80
Dim temp As New Bitmap(newWidth, newHeight)
Dim newImage As Graphics = Graphics.FromImage(temp)
newImage.DrawImage(fullImage, 0, 0, newWidth, newHeight)
temp.Save((savepath + "\thumbs" & "\") + "t_" + filename)
context.Response.Write("<a href='" + (tempPath & "/") + filename + "'><img src='" + tempPath + "/thumbs" & "/" + "t_" + filename + "'/></a>")
context.Response.StatusCode = 200
'context.Response.Write("OK")
End Sub
Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
Get
Return False
End Get
End Property
End Class在上面的代码中,你可以找到用户上传时附加的缩略图,你可以找到图像的缩略图。
发布于 2011-11-05 16:26:45
如果要刷新更新面板,请尝试执行以下操作...
UpdatePanel1.Update();如果为页面启用了部分页面呈现,则在调用Update方法时,将在浏览器中更新UpdatePanel控件的内容。如果有必须执行以确定是否应更新UpdatePanel控件的服务器代码,请调用Update方法。如果计划使用Update方法,请将UpdateMode属性设置为Conditional。如果希望在服务器逻辑中决定是否更新面板,请确保ChildrenAsTriggers属性为false,并且没有为面板定义显式触发器。
在典型的页开发方案中,如果定义触发器,或者如果UpdatePanel控件的ChildrenAsTriggers属性为true,则在页生命周期期间会自动调用Update方法。
如果没有为UpdatePanel控件定义ContentTemplate属性,则不会更新面板。
https://stackoverflow.com/questions/8018979
复制相似问题