Aktham Mahmoud

Aktham Mahmoud

  • NA
  • 720
  • 38.1k

Access to control in Detailsview By Javascript

Dec 25 2019 6:06 AM
Greeting All I Used Detailsview Control to insert form data. In DetailsView has upoladfile control to upload image. I used JavaScript method to show image before upload it. Like that example [https://www.youtube.com/watch?v=DX3ZoZZ1se8][1]
 
If apply same example without Detailsview everything good.
 
Problem: If apply same javascript on uploadfile in detilsview cant work: that's code below:
  1. <script type="text/javascript">  
  2. function ImagePreview(input) {  
  3. if (input.files && input.files[0]) {  
  4. var reader = new FileReader();  
  5. reader.onload = function (e) {  
  6. $('<%# ((DV_AddEmployee).FindFieldTemplate("Photo").FindControl("Image1")).ClientID %>').prop('src', e.target.result)  
  7. .width(90)  
  8. .height(90);  
  9. };  
  10. reader.readAsDataURL(input.files[0]);  
  11. }  
  12. }  
  13. </script>  
and that's id DetilsView code:
  1. <asp:DetailsView ID="DV_Add" runat="server" Height="50%" Width="50%" DefaultMode="Insert" AutoGenerateRows="False" DataKeyNames="Id" OnItemCommand="DV_Add_ItemCommand">  
  2. <Fields>  
  3. <asp:TemplateField HeaderText="Photo:">  
  4. <InsertItemTemplate>  
  5. <asp:FileUpload ID="FileUpload1" runat="server" onchange="ImagePreview(this)" />  
  6. <asp:Image ID="Image1" runat="server" />  
  7. <br />  
  8. </InsertItemTemplate>  
  9. </asp:TemplateField>  
  10. <asp:TemplateField>  
  11. <InsertItemTemplate>  
  12. <asp:Button ID="BtnInsert" runat="server" Text="Insert" CommandName="AddNew" />  
  13. <asp:Button ID="Btncancel" runat="server" Text="Cancel" CommandName="Cancel" />  
  14. </InsertItemTemplate>  
  15. </asp:TemplateField>  
  16. </Fields>  
  17. </asp:DetailsView>  
  18. <asp:DetailsView ID="DV_Add" runat="server" Height="50%" Width="50%" DefaultMode="Insert" AutoGenerateRows="False" DataKeyNames="Id" OnItemCommand="DV_Add_ItemCommand"> <Fields> <asp:TemplateField HeaderText="Photo:"> <InsertItemTemplate> <asp:FileUpload ID="FileUpload1" runat="server" onchange="ImagePreview(this)" /> <asp:Image ID="Image1" runat="server" /> <br /> </InsertItemTemplate> </asp:TemplateField> <asp:TemplateField> <InsertItemTemplate> <asp:Button ID="BtnInsert" runat="server" Text="Insert" CommandName="AddNew" /> <asp:Button ID="Btncancel" runat="server" Text="Cancel" CommandName="Cancel" /> </InsertItemTemplate> </asp:TemplateField> </Fields> </asp:DetailsView>  
Am trying many ways to access to controls image in detailsview (template)(row) no way..
 
Thanks or help

Answers (3)