0

我正在使用 Uploadify v2.1.4 使用 ASP.Net C# FM 4.0 上传图像。

在此页面中,我还有其他控件,但我想要一种功能,即当我上传图像时,它应该自动刷新 UpdatePanel1 以显示上传的图像

默认.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# 做到这一点

请建议我如何执行此代码示例,我们将不胜感激。

问候

4

2 回答 2

2

如果您想刷新更新面板,试试这个...

UpdatePanel1.Update();

如果页面启用了部分页面呈现,当您调用 Update 方法时,UpdatePanel 控件的内容会在浏览器中更新。如果您有必须执行以确定是否应更新 UpdatePanel 控件的服务器代码,请调用 Update 方法。如果您计划使用 Update 方法,请将 UpdateMode 属性设置为 Conditional。如果您希望在服务器逻辑中确定更新面板的决定,请确保 ChildrenAsTriggers 属性为 false,并且没有为面板定义显式触发器。

在典型的页面开发场景中,如果您定义了触发器,或者如果 UpdatePanel 控件的 ChildrenAsTriggers 属性为 true,则在页面生命周期中会自动调用 Update 方法。

如果没有为 UpdatePanel 控件定义 ContentTemplate 属性,则不会发生面板更新。

于 2011-11-05T08:26:45.120 回答
1

Try by showing the image by using the response after the Onupload complete event.So when the user as soon as he uploads you will find the image.

This is the script:

<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>

This is the Handler:

<%@ 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

In the above code you can find thumbnails appended as soon as the user uploads you find a thumbnail of the image.

于 2011-11-05T08:57:11.617 回答