0

I have html control as fileuploaderand i add runat="server" to it to access it at server side, I don't want to user asp:FileUploader because of its bad css style especially in bootstrap

<span>
<input type="file" runat="server" id="File_Upload" />
</span>

Now i need to get image from this html fileUploder to save it in database I got example code from google to get image from fileuploader as

Byte[] imgbyte = null;
if (File_Upload.PostedFile != null)
{
    HttpPostedFile file = File_Upload.PostedFile;
    imgbyte = new Byte[file.ContentLength];
    file.InputStream.Read(imgbyte, 0, file.ContentLength);
 }

but when i examine by using breakpoint then compiler does not enter into IF body because of Null vaule

I also used this

 ScriptManager.GetCurrent(this).RegisterPostBackControl(this.File_Upload);

in Form_Load Event due to using asp:UpdatePanel

but i didn't get file (Image) from FileUploader

I need your help to solve this issue..

Thanks in advance.

EDIT:

When i remove asp:UpdatePanel then i can access file that i select.

and also use

<Triggers>
      <asp:PostBackTrigger ControlID="File_Upload" />
   </Triggers>

Solution:

Mistakenly i used FileUploader's ID and by following @Suprabhat's suggestion i change it as

<Triggers>
              <asp:PostBackTrigger ControlID="btnCreate" />
           </Triggers>

and now working fine..

Waqas
  • 847
  • 4
  • 14
  • 36
  • 1
    So, you have added **PostBackTrigger** but **ControlID** should include the name of button which is sending a post message not the name of file upload control id that is selecting a file. – Suprabhat Biswal Sep 21 '15 at 08:10
  • Oh.... sorry i didn't notice that.. thanks for your time ... now its working – Waqas Sep 21 '15 at 08:15

1 Answers1

0

Try adding enctype="multipart/form-data" attribute to your form element.