可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
i am using AjaxFileUpload in ASP.NET 4.0 website. The problem is that when i upload a file its UploadComplete fires which causes a postback to page. on every postback caused by AjaxFileUpload the Ispostback property is False which should be True. What is the reason. I checked it in the updatePanel and without it. It has no affect at it. Here is the
<ajax:AjaxFileUpload ID="AjaxFileUpload1" ContextKeys="fred" AllowedFileTypes="jpg,jpeg,png,gif" MaximumNumberOfFiles="3" runat="server" OnUploadComplete="AjaxFileUpload1_UploadComplete" />
回答1:
To detect postback from the AjaxFileUpload use this control's property: AjaxFileUpload.IsInFileUploadPostBack. The IsPostBack property doesn't works because this control submits not to the same page where is was rendered but to hidden frame instead so it's the first time for frame it loading on server. See more in AjaxControlToolkit sources: AjaxControlToolkit AjaxFileUpload
回答2:
Its a direct solution code of this problem
protected void Page_Load(object sender, EventArgs e) { // check if postback came through AjaxFileUpload control if (AjaxFileUpload1.IsInFileUploadPostBack) { // do for ajax file upload partial postback request } else { // do for normal page request } }