FileUpload image preview javascript not working in IE7/Firefox

Last post 08-07-2009 8:54 AM by sandymca94. 0 replies.

Sort Posts:

  • FileUpload image preview javascript not working in IE7/Firefox

    08-07-2009, 8:54 AM
    • Member
      point Member
    • sandymca94
    • Member since 09-18-2006, 5:00 AM
    • Posts 3

    Hi

    In my application i have a registration page in which FileUpload image preview functionality is required. I implemented below javascript code which is working IE6 but this code is not working on IE7 and firefox so if any budy have some idea please help me i need it in urgent and i am stuck with this problem from last 2 weeks.

    And i also tried the web custom control to implement the image preview functionality but this is also not working because i am using master page concept that's why it is not workong, in case of master page what i need to mention here...TargetFormID="Your form name where u want to see the file upload control".

    Here is the link to see whole code...    http://rebootoff.blogspot.com/2008/04/javascript-image-uploadpreview-without.html

    and here is the my javascript code ..


    function imgload()
    {
       var filePath = document.getElementById('<%=ctrlFileUpLoad1.ClientID%>');
       var DefaultAd = document.getElementById ('<%=ctrlDefaultAd.ClientID%>');
       var path = "file:\/\/\/" + filePath.value;
       path = path.toLowerCase();
        if (path.substring(0,path.lastIndexOf('.png'))||path.substring(0,path.lastIndexOf('.jpg'))||path.substring(0,path.lastIndexOf('.jpeg'))||path.substring             (0,path.lastIndexOf('.gif'))){
        var img=document.createElement('img');
        img.setAttribute('src',path);
        document.getElementById('imageprv').appendChild(img);

    }}

    // .aspx code

     <td>
     <asp:FileUpload ID="ctrlFileUpLoad1" runat="server" OnChange="javascript:imgload();" />
                                                   
     <asp:CustomValidator ID="CustomValidator1" ControlToValidate="ctrlFileUpLoad1" Display="dynamic"
      ClientValidationFunction="ValidateFile" runat="server" ErrorMessage="Only images are permitted">                                
      </asp:CustomValidator>
     <asp:RequiredFieldValidator ID="RequiredFieldValidator13" runat="server" ControlToValidate="ctrlFileUpLoad1"
     ErrorMessage="Please select the image"></asp:RequiredFieldValidator>
                                                        
     <div id="imageprv" style="width: 475px;">
                                                       
                                                        
    </div>
    </td>

    Filed under:
Page 1 of 1 (1 items)