0

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#を使用してそれを行う方法の例を教えてください

このコードサンプルをどのように実行できるかアドバイスしていただければ幸いです。

よろしく

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

Onupload completeイベント後の応答を使用して画像を表示してみてください。したがって、ユーザーがアップロードするとすぐに画像が見つかります。

これはスクリプトです:

<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-05T08:57:11.617 に答える