2015-06-08 52 views
1

我知道这个问题很常见,但在我的情况下,我涉及到一个JavaScript,所以这可能是问题。这是我正在做的。我打电话给asp文件上传允许用户选择一个图像。然后通过调用onchange事件,我发射了一个javascript,从而使隐藏的div变得可见。该div包含一个确认按钮,然后触发上传功能:FileUpload HasFile返回false

<div class="profile-page-owner-profile-pic"> 
     <asp:FileUpload ID="profile_pic_input" onchange="profilenewimageinput(this)" runat="server"></asp:FileUpload> 
</div> 

隐藏事业部:

<div id="profile-change-profile-pic-bg-overlay-div"> 
    <div class="profile-change-profile-pic-bottom-bar"> 
      <asp:Button ID="picApply" class="cropButton" runat="server" OnClick="picApply_Click" Text="Button" /> 
      <span class="profile-page-cancel-crop-button" onclick="hideprofilepicwindow()">Cancel</span> 
     </div> 
</div> 

JS:

function profilenewimageinput() { 

    document.getElementById("profile-change-profile-pic-bg-overlay-div").style.display = "block"; 

    setTimeout(function() { 

     document.getElementById("profile-change-profile-pic-bg-overlay-div").style.opacity = 1; 

    }, 100); 

} 

后面的代码:

protected void picApply_Click(object sender, EventArgs e) 
{ 
    if (profile_pic_input.HasFile) //always returns false when debugged 
    { 
      //Code 
    } 
} 

为什么我的HasFile总是返回False ev当选择图像时?

回答

0

尝试将其置于<asp:UpdatePanel>并使用适当的Trigger设置。以下可能有效,但我不在某个地方测试:

<div class="profile-page-owner-profile-pic"> 
    <asp:UpdatePanel ID="UploadPanel" runat="server"> 
     <Triggers> 
      <asp:PostBackTrigger ControlID="picApply" /> 
     </Triggers> 
     <ContentTemplate> 
      <asp:FileUpload ID="profile_pic_input" onchange="profilenewimageinput(this)" runat="server" /> 
     </ContentTemplate> 
    </UpdatePanel> 
</div>