"If at first you don't succeed; call it version 1.0" :-Unknown

Pages

Thursday, May 13, 2010

FileUpload inside the Ajax UpdatePanel

Hi eveybody,
From my last projects i notice that file-upload not working with Ajax update panel.It showing me an error "Object reference is not an instance of object".So i make little study then i know that the file upload control  inside the update-panel and upload the file then FileUpload1.Hasfile is always false because file upload control is inside updatepanel then your file upload control does not post back. Because the file upload control works only when the full page postback. If you want to upload the file then you need to postback the page.


So we need to create the PostBackTrigger for the button.

We place <trigger> between <updatepanel> and <contenttemplate>

<asp:updatepanel id="UpdatePanel1" runat="server">
<contenttemplate>
<asp:fileupload id="FileUpload1" runat="server">
<asp:button id="btnSubmit" runat="server" text="Upload">
</asp:button>

</contenttemplate>
<triggers>
<asp:postbacktrigger controlid="btnSubmit">
</asp:postbacktrigger>
</triggers>

</updatepanel>
Triggers allow us to force a post back.


Have a nice day... 'N happy Coding :)
 Programming ASP.NET AJAX: Build rich, Web 2.0-style UI with ASP.NET AJAXProfessional ASP.NET 3.5 AJAX (Wrox Programmer to Programmer)Programming ASP.NET AJAX

No comments: