I DONT WANNA GET MY PAGE TO BE GET REFRESH OR POSTBACK
我不想让我的页面被刷新或回发。
So I am trying uploading file in updatepanel but onclicking upload button the validation check shows that there is no file
我正在尝试在updatepanel中上传文件,但是在单击upload按钮时,验证检查显示没有文件
my html code is
我的html代码是
<asp:UpdatePanel ID="UpdatePanel16" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:FileUpload ID="fp_upload" runat="server" />
<asp:Button ID="btn_browse" runat="server" Text="Upload" OnClick="btn_browse_Click" />
</ContentTemplate>
</asp:UpdatePanel>
It seems to be
这似乎是
my .cs code is
我的cs的代码是
protected void btn_browse_Click(object sender, EventArgs e)
{
if (fp_upload.HasFile)
{
Response.Write("contains file");
}
else
{
Response.Write("no file");
}
}
when I used to browse the file and click on upload button every times it goes in else condition. Whats the problem.
当我经常浏览文件并每次在else条件下点击上传按钮时。什么问题。
ALSO I DONT WANNA GET MY PAGE TO BE GET REFRESH OR POSTBACK
我也不想让我的页面被刷新或回发
3 个解决方案
#1
2
To use a FileUpload control inside an UpdatePanel control, set the postback control that submits the file to be a PostBackTrigger control for the panel.
要在UpdatePanel控件中使用FileUpload控件,请将提交文件的postback控件设置为面板的PostBackTrigger控件。
#2
0
Write trigger will instruct the button that we are using for the upload to perform a full postback
写触发器将指示我们用于上载的按钮执行完整的回发
<asp:UpdatePanel ID="UpdatePanel16" runat="server">
<Triggers>
<asp:PostBackTrigger ControlID="btn_browse" />
</Triggers>
<ContentTemplate>
<asp:FileUpload ID="fp_upload" runat="server" />
<asp:Button ID="btn_browse" runat="server" Text="Upload" OnClick="btn_browse_Click" />
</ContentTemplate>
</asp:UpdatePanel>
#3
0
just add PostBackTrigger
after </ContentTemplate>
for the FileUploader
as below:
在之后,为FileUploader添加PostBackTrigger,如下所示:
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="FileUpload1" />
</Triggers>
</asp:UpdatePanel>
and add the below code in page load :
并在页面加载中添加如下代码:
ScriptManager.GetCurrent(this).RegisterPostBackControl(FileUpload1);
or if you want to make it async, you can use this :
或者如果你想让它异步,你可以这样做:
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:Button ID="btnAsyncUpload" runat="server"
Text="Async_Upload" OnClick = "Async_Upload_File" />
<asp:Button ID="btnUpload" runat="server" Text="Upload"
OnClick = "Upload_File" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID = "btnAsyncUpload"
EventName = "Click" />
<asp:PostBackTrigger ControlID = "btnUpload" />
</Triggers>
</asp:UpdatePanel>
#1
2
To use a FileUpload control inside an UpdatePanel control, set the postback control that submits the file to be a PostBackTrigger control for the panel.
要在UpdatePanel控件中使用FileUpload控件,请将提交文件的postback控件设置为面板的PostBackTrigger控件。
#2
0
Write trigger will instruct the button that we are using for the upload to perform a full postback
写触发器将指示我们用于上载的按钮执行完整的回发
<asp:UpdatePanel ID="UpdatePanel16" runat="server">
<Triggers>
<asp:PostBackTrigger ControlID="btn_browse" />
</Triggers>
<ContentTemplate>
<asp:FileUpload ID="fp_upload" runat="server" />
<asp:Button ID="btn_browse" runat="server" Text="Upload" OnClick="btn_browse_Click" />
</ContentTemplate>
</asp:UpdatePanel>
#3
0
just add PostBackTrigger
after </ContentTemplate>
for the FileUploader
as below:
在之后,为FileUploader添加PostBackTrigger,如下所示:
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="FileUpload1" />
</Triggers>
</asp:UpdatePanel>
and add the below code in page load :
并在页面加载中添加如下代码:
ScriptManager.GetCurrent(this).RegisterPostBackControl(FileUpload1);
or if you want to make it async, you can use this :
或者如果你想让它异步,你可以这样做:
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:Button ID="btnAsyncUpload" runat="server"
Text="Async_Upload" OnClick = "Async_Upload_File" />
<asp:Button ID="btnUpload" runat="server" Text="Upload"
OnClick = "Upload_File" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID = "btnAsyncUpload"
EventName = "Click" />
<asp:PostBackTrigger ControlID = "btnUpload" />
</Triggers>
</asp:UpdatePanel>