如何在ASP更新面板中使用telerik RadAsyncUpload和RadBinaryImage预览上传的图像?

时间:2012-11-15 16:37:09

标签: image telerik updatepanel radupload

我在asp.net中有一个Web表单包含一个RadAsyncfileupload和一个Asp Update Panel中的RadBinaryImage,如下所示

<body>
    <form id="form1" runat="server">
     <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <div>

    <asp:UpdatePanel runat="server">

<ContentTemplate>

    <telerik:RadAsyncUpload ID="RadAsyncUpload1" runat="server">
    </telerik:RadAsyncUpload>
    <telerik:RadBinaryImage ID ="RadBinaryImage1" runat ="server" Width= "100px" Height="100px"/>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>

中的代码

  protected void RadAsyncUpload1_FileUploaded(object sender, Telerik.Web.UI.FileUploadedEventArgs e)
        {
            if (RadAsyncUpload1.UploadedFiles.Count == 1)
            {
                byte[] image;
                long fileLength = RadAsyncUpload1.UploadedFiles[0].InputStream.Length;
                image = new byte[fileLength];
                RadAsyncUpload1.UploadedFiles[0].InputStream.Read(image, 0, image.Length);
                RadBinaryImage1.DataValue = image;

            }

        }

但在运行时程序控制器不会触发RadAsyncUpload1_FileUploaded事件 我已经搜索了Telerik论坛,发现我应该对脚本管理器做一些事情,但我需要一些帮助来解决这个问题的原因是,为了解决这个事件,整个页面应该回发,无论如何一些脚本可以帮助我或任何其他方法! 提到我需要图像的字节数组来保存在DB中。 提前致谢 Saeed Soleimanifar

1 个答案:

答案 0 :(得分:5)

http://demos.telerik.com/aspnet-ajax/asyncupload/examples/persistuploadedfiles/defaultvb.aspx?#qsf-demo-source

我刚刚使用此功能添加了相同的功能,如果您发现任何问题,请告诉我... 要么 这是魔术的部分

页面来源:

<telerik:RadScriptBlock ID="RadScriptBlock1" runat="server">

    <script type="text/javascript">


        function updatePictureAndInfo() {

            __doPostBack('btnImgUpload', 'RadButton1Args');

        }

    </script>

</telerik:RadScriptBlock>

<telerik:RadBinaryImage runat="server" ID="imgBinaryPhoto" ImageUrl="~/Images/default-profile-pic.png"
                Width="100px" Height="100px" ResizeMode="Fit" AlternateText="No picture available"
                CssClass="preview"></telerik:RadBinaryImage>
            <br />
            <telerik:RadAsyncUpload ID="upldPhoto" runat="server" AllowedFileExtensions=".jpg,.png,.gif,jpeg,.tiff"
               MaxFileInputsCount="1" MultipleFileSelection="Disabled">
            </telerik:RadAsyncUpload>
            <asp:Button ID="btnImgUpload" runat="server" Text="Upload" CssClass="button" OnClientClick="updatePictureAndInfo(); return false;" />

代码背后:

Protected Sub FileUploaded() Handles upldPhoto.FileUploaded

        Dim bitmapImage As Bitmap = ResizeImage(upldPhoto.UploadedFiles(0).InputStream)
        Dim stream As System.IO.MemoryStream = New System.IO.MemoryStream()
        bitmapImage.Save(stream, System.Drawing.Imaging.ImageFormat.Bmp)
        imgBinaryPhoto.DataValue = stream.ToArray()

    End Sub