Click here to Skip to main content
15,885,985 members
Please Sign up or sign in to vote.
2.67/5 (2 votes)
See more:
Here I use ajax fileupload.when select the file the error is occured like "unhandled exception.The file attached is invalid".




ASP.NET
<asp:DataList ID="DataList1" runat="server" RepeatDirection="Horizontal"         RepeatColumns="4" width="100%"  >
  <ItemTemplate>	
  <table width="98%" border="0" cellspacing="0" cellpadding="0" align="center">
  <tr>
  <td align="center">
  <asp:ImageButton ID="gallery" runat="server"  ImageUrl='<%# Eval("photo") %>'    width="180" height="200" CssClass="img-responsive img-thumbnail" />
 <asp:AsyncFileUpload ID="AsyncFileUpload1" runat="server" Width="180" CompleteBackColor="White"  ThrobberID="imgLoad" OnUploadedComplete="doUpload"  />
  <asp:Image ID="imgLoad" runat="server" imgurl="loading.jif"  Visible="false"/>
  
  <asp:Label ID="imageid" runat="server" Text='<%#Eval("proimg_id") %>'                         Visible="false" ></asp:Label>
  
  </td>
  </tr>
  <tr>
    <td align="center"> </td>
    
  </tr>
  <tr>
     <td align="center"> </td>
   </tr>
          </table>
		 
</ItemTemplate>
 </asp:DataList>


C#
public void gallery()
  {
      try
      {
          DataSet ds = new DataSet();
          obj.type = 4;
         //select photo,proimg_id from tbl_photos
          ds = obj.bind();
          DataList1.DataSource = ds;
          DataList1.DataBind();
      }
      catch(Exception ex)
      {
          Response.Write (ex.ToString());
      }
    }

 protected void doUpload(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e)
 {
   AjaxControlToolkit.AsyncFileUpload lbl =(AjaxControlToolkit.AsyncFileUpload)sender;
   DataListItem container = (DataListItem)lbl.NamingContainer;
   Label imageid1 = (Label)container.FindControl("imageid");
   obj.proimgid = int.Parse(imageid1.Text);
   AsyncFileUpload file1 = (AsyncFileUpload)container.FindControl("AsyncFileUpload1");
   b = file1;
   filename1 = b.PostedFile.FileName;
   b.SaveAs(Server.MapPath("../Upload/" + filename1));
   obj.photoname = "../Upload/" + filename1.ToString();
   obj.type = 5;
   result=obj.Execute();
   //update query 
   //update tbl_photos set photo=@photoname where proimg_id=@proimgid 
   if (result > 0)
      {
          gallery();  
      }
 }



i add clientidmode="autoid". but it does not work properly.how to solve this?
then i use .net 3.5 version
Posted
Updated 23-Mar-15 1:56am
v3
Comments
King Fisher 23-Mar-15 7:57am    
Please be patient Manoj ,you will get it.
ZurdoDev 23-Mar-15 11:41am    
If you google that error there are lots of results and several things you'll need to try.
ManojanbU 24-Mar-15 8:02am    
i fix web config file
<pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID"/>
but web config is not accept the tag.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900