I have asp:FileUpload
, two asp:Button
, and GridView
in UpldatePanel
.
<asp:FileUpload runat="server" ID="fileExcelUpload" />
<asp:Button ID="btnShow" runat="server" Width="80px" OnClick="btnShow_Clicked"
AutoPostBack="true" Text="Save"/>
<asp:Button ID="btnImport" runat="server" Width="80px" OnClick="btnImport_Clicked"
AutoPostBack="true" Text="Save"/>
<asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional">
<ContentTemplate>
.........GridView...........
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnShow" EventName="Click" />
<asp:AsyncPostBackTrigger ControlID="btnImport" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
Firstly , I retrieve some data from database and bind to gridView
using btnShow
.It works perfectly.
But when I upload Excel file with asp:FileUpload
and click btnImport
,
protected void btnImport_Clicked(object sender, EventArgs e)
{
if (fileUExcelUpload.HasFile)
{
.....
}
}
the boolean value fileUExcelUpload.HasFile
return False
.
But when I remove <asp:AsyncPostBackTrigger ControlID="btnImport" EventName="Click" />
from UpldatePanel's triggers , it return True
.
(The reason why I add btnImport
's Click event to UpdatePanel's Triggers is , I want to persist Uploaded File of asp:FileUpload
after postback . )
Is there any right way to do it ? Kindly help me Please :) Thanks !
Add this line in the
<Triggers> </Triggers>
<asp:PostBackTrigger ControlID="btnUpload" />
here btnUpload is the id of the fileupload control
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.