c# - Can't upload file inside an asp:formview inside an asp:UpdatePanel? -
this aspx file:-
<ajaxtoolkit:modalpopupextender id="modalprogress" runat="server" targetcontrolid="panelupdateprogress" backgroundcssclass="modalbackground" popupcontrolid="panelupdateprogress" /> <asp:updatepanel id="updatepanel1" runat="server"> <contenttemplate> <asp:formview id="formviewreg" runat="server" width="100%" allowpaging="false" onitemupdating="formviewreg_itemupdating"> <edititemtemplate> <asp:linkbutton id="lbtnupdatepersonal" runat="server" onclick="lbtnupdatepersonal_click" validationgroup="g1">update</asp:linkbutton> <asp:fileupload id="fileupload1" runat="server" /> </edititemtemplate> <itemtemplate> <asp:linkbutton id="lbtneditpersonal" runat="server" onclick="lbtneditpersonal_click">edit</asp:linkbutton> //some html controls </itemtemplate> </asp:formview> </contenttemplate> </asp:updatepanel>
what i've tried trying access file in fileupload1 placing inside edititemtemplate block placing outside i.e. outside formview , outside updatepanel. in no way fileupload1.hasfile returns true. there way can work around process. want access fileupload1's file on clicking lbtnupdatepersonal using in aspx.cs file:-
protected void lbtnupdatepersonal_click(object sender, eventargs e) { if (fileupload1.hasfile)//returns false { viewstate["imageext"] = uploadfile1(fileupload1.postedfile, "studentphoto/"); } formviewreg.updateitem(false); }
fileupload1.hasfile doesn't returns true.
that's because inorder send file server have perform full postback.since file upload control inside updatepanel restricting upload file.
to make work either have remove updatepanel shared mark-up or explicitly register event file upload using formview databound event.
protected void formviewreg_databound(object sender, eventargs e) { if (formviewreg.currentmode == formviewmode.edit) { fileupload fu = e.row.findcontrol("fileupload1") fileupload; scriptmanager.getcurrent(this).registerpostbackcontrol(fu); } }
note: need include script manager within in form before using it.
<asp:scriptmanager id="scriptmanager" runat="server"></asp:scriptmanager>
Comments
Post a Comment