Friday, 27 July 2012

Upload Image and show preview without clicking any button manually

Upload Image and show preview without clicking any Button Manually

In .aspx page Directory:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="FileUpload.aspx.cs" Inherits="RadUpload.FileUpload" EnableEventValidation="false" %>


 <script language="javascript">

        function Change(obj) {
            __doPostBack("<%= Button1.ClientID %>", "");

<asp:UpdatePanel ID="UPanel" runat="server">
                <table width="100%">
                        <td align="center">
                            <img id="imgUploadImage" runat="server" style="height: 200px; width: 200px;" />
                        <td align="center">
                            <asp:FileUpload ID="FileUpload1" runat="server" onchange="Change(this);" />
                            <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button"                Visible="False" />
                <asp:AsyncPostBackTrigger ControlID="Button1" EventName="Click" />

CodeBehind Page

protected void Button1_Click(object sender, EventArgs e)
            int FileSize = FileUpload1.PostedFile.ContentLength;
            byte[] bytFileBinary = new byte[FileSize];
            FileUpload1.PostedFile.InputStream.Read(bytFileBinary, 0, (int)FileUpload1.PostedFile.ContentLength);
            imgUploadImage.Src = "data:image/png;base64," + Convert.ToBase64String(bytFileBinary);

final Out Put :


  1. For me its getting refresh,I am using master page also