Asp.net C#-Ajax中代码隐藏函数调用的更新面板刷新

Asp.net C#-Ajax中代码隐藏函数调用的更新面板刷新,asp.net,ajax,c#-4.0,partial-page-refresh,partial-postback,Asp.net,Ajax,C# 4.0,Partial Page Refresh,Partial Postback,我正在使用UploadifyV2.1.4使用ASP.NETC#FM4.0上传图像 在这个页面中,我还有其他控件,但我想要一个功能,当我上传图像时,它应该自动刷新UpdatePanel1以显示上传的图像 Default.aspx文件 <asp:UpdatePanel ID="UpdatePanel1" runat="server" > <ContentTemplate> <asp:

我正在使用UploadifyV2.1.4使用ASP.NETC#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>
所以,当我上传图像时,它应该刷新网格的部分页面更新。请给我一个例子,我如何可以做它使用C#

请建议我如何做这个代码样本将不胜感激


如果要刷新更新面板,请尝试以下操作

UpdatePanel1.Update();
如果页面已启用部分页面呈现,则在调用 方法中更新UpdatePanel控件的内容 浏览器如果您的服务器代码必须 执行以确定是否应更新UpdatePanel控件。 如果计划使用Update方法,请将UpdateMode属性设置为 有条件的如果您希望更新面板的决定 在服务器逻辑中确定,请确保ChildrenAsTriggers 属性为false,并且没有为 小组

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

如果未为UpdatePanel定义ContentTemplate属性 控件,则不会更新面板


如果要刷新更新面板,请尝试以下操作

UpdatePanel1.Update();
如果页面已启用部分页面呈现,则在调用 方法中更新UpdatePanel控件的内容 浏览器如果您的服务器代码必须 执行以确定是否应更新UpdatePanel控件。 如果计划使用Update方法,请将UpdateMode属性设置为 有条件的如果您希望更新面板的决定 在服务器逻辑中确定,请确保ChildrenAsTriggers 属性为false,并且没有为 小组

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

如果未为UpdatePanel定义ContentTemplate属性 控件,则不会更新面板


尝试在Onupload完成事件后使用响应显示图像。因此,当用户一上传,您就会找到图像

以下是脚本:

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

$(窗口)。加载(
函数(){
$(“#文件输入1”)。上载({
'uploader':'scripts/uploadify.swf',
'cancelImg':'images/cancel.png',
'buttonText':'Browse Files',
'script':'Upload.aspx',
'文件夹':'上载',
'fileDesc':'Image Files',
“fileExt”:“*.jpg;*.jpeg;*.gif;*.png”,
'queueSizeLimit':9999,
“simUploadLimit”:2,
“sizeLimit”:4000000,
"多":对,,
“自动”:正确,
“onComplete”:函数(事件、队列ID、fileObj、响应、数据){
$(“#缩略图”).append(响应)
},
“onError”:函数(事件、ID、fileObj、errorObj){
警报(errorObj.type+'Error:'+errorObj.info);
}
});
}
);
这是处理程序:

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

导入系统
导入系统.Web
导入System.IO
导入系统。绘图
公共类UploadVB:实现IHttpHandler
Public Sub-ProcessRequest(ByVal上下文作为HttpContext)实现IHttpHandler.ProcessRequest
Dim postedFile作为HttpPostedFile=context.Request.Files(“文件数据”)
Dim savepath As String=“”
Dim tempPath As String=“”
tempPath=System.Configuration.ConfigurationManager.AppSettings(“FolderPath”)
savepath=context.Server.MapPath(tempPath)
Dim文件名为String=postedFile.filename
如果目录不存在(保存路径),则
CreateDirectory(保存路径)
如果结束
如果目录不存在(savepath+“\thumbs”),则
目录.CreateDirectory(保存路径+“\thumbs”)
如果结束
postedFile.SaveAs((savepath&“\”)+文件名)
将fullImage设置为System.Drawing.Image=新的System.Drawing.位图((保存路径和“\”)+文件名)
Dim newWidth为整数=100
将新高度调整为整数=80
作为新位图的Dim temp(新宽度、新高度)
Dim newImage As Graphics=Graphics.FromImage(临时)
DrawImage(fullImage,0,0,newWidth,newHeight)
临时保存((保存路径+“\thumbs”&“\”+“t\”+文件名)
context.Response.Write(“”)
context.Response.StatusCode=200
'context.Response.Write(“OK”)
端接头
公共只读属性IsReusable()作为布尔值实现IHttpHandler.IsReusable
得到
返回错误
结束
端属性
末级

在上面的代码中,您可以在用户上传后立即找到附加的缩略图,您可以找到图像的缩略图。

尝试在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>

$(窗口)。加载(
函数(){
$(“#文件输入1”)。上载({
'uploader':'scripts/uploadify.swf',
'cancelImg':'images/cancel.png',
'buttonText':'Browse Files',
'script':'Upload.aspx',
'文件夹':'上载',
'fileDesc':'Image Files',
“fileExt”:“*.jpg;*.jpeg;*.gif;*.png”,
'queueSizeLimit':9999,
“simUploadLimit”:2,
“sizeLimit”:4000000,
"多":对,,
“自动”:正确,
“onComplete”:函数(事件、队列ID、fileObj、响应、数据){
$(“#t