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


 <script language="javascript">

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


<asp:UpdatePanel ID="UPanel" runat="server">
            <ContentTemplate>
                <table width="100%">
                    <tr>
                        <td align="center">
                            <img id="imgUploadImage" runat="server" style="height: 200px; width: 200px;" />
                        </td>
                    </tr>
                    <tr>
                        <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" />
                        </td>
                    </tr>
                </table>
            </ContentTemplate>
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="Button1" EventName="Click" />
            </Triggers>
        </asp:UpdatePanel>


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 :





Related Posts:

  • Replace characters in javascript In server side we have "Replace" method to replace the characters in a string but on javascript replace method will be not useful in certain cases instead of that we can do for loop to replace the particular characters and g… Read More
  • Different Culture Names CULTURE ||SPEC.CULTURE||ENGLISH NAME af af-ZA Afrikaans af-ZA af-ZA Afrikaans (South Africa) ar ar-SA Arabic ar-AE ar-AE Arabic (U.A.E.) ar-BH ar-BH Arabic … Read More
  • Culture info in RadDateTime Picker In this example we can give culture info for localization in RadDatetimePicker. for this below example u can get different localizations according to their country. it is one of the property in RadDateTimePicke… Read More
  • Word Documents and Excel Documents in IFRAME In this below example we are converting word OR excel document to HTML. In this case we are converting and giving converted HTML file as ""src"" to ""iframe"". Step By Step Procedure : 1)First step is create one… Read More
  • Word document in iframe This is screen shot for iframe.Here In the below Screenshot iframe viewing the word document in the form of html. so i am giving html to the Iframe src. Iframe can view excel,csv,pdf,text file… Read More

1 comments:

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

    ReplyDelete