2013-06-20 21 views
0

我有用戶控件,其中包含具有候選數據的網格。有一個列模板字段鏈接按鈕的候選人名稱。我附加了一個rowcommand事件,我正在下載一個word文件。我已經下載了從簡單的網頁下載我的doc文件的doc文件代碼,但是這個代碼在用戶控制上不起作用。任何人都可以幫我解決這個問題。它給人錯誤沒有獲得響應Doc文件不從asp.net中的UserControl下載

<asp:GridView ID="grdCandidate" runat="server" AutoGenerateColumns="false" 
     OnRowDataBound="grdCandidate_RowDataBound" 
     onrowcommand="grdCandidate_RowCommand"> 
      <Columns> 
      <asp:BoundField DataField="Candidate ID" HeaderText="Candidate ID" /> 
       <asp:TemplateField> 
         <HeaderTemplate> 
          Candidate Name 
         </HeaderTemplate> 
        <ItemTemplate> 
          <asp:LinkButton ID="lnkResume" CommandName="Download" CommandArgument='<%#Eval("Candidate ID") %>' 
           runat="server" Text='<%#Eval("Candidate Name") %>' ToolTip='<%# "Download Resume - " + Eval("Candidate Name") %>'></asp:LinkButton> 
        </ItemTemplate> 
       </asp:TemplateField> 
      </Columns> 
</asp:GridView> 

protected void grdCandidate_RowCommand(object sender, GridViewCommandEventArgs e) 
{ 
    try 
    { 
     if (e.CommandName == "Download") 
     { 
      byte[] Attachment = null; 
      string Extension = string.Empty; 
      string Resume = "Resume"; 
      ClsCandidateManager objCandidateManager = new ClsCandidateManager(); 
      ClsSecureManager objSecureManager = new ClsSecureManager(); 
      Attachment = objCandidateManager.GetCandidateAttachment(Convert.ToInt32(e.CommandArgument), out Extension); 
      if (Attachment != null && Attachment.Length > 0) 
      { 
       try 
       { 
        Response.Clear(); 
        Response.Buffer = true; 
        Response.Charset = ""; 
        if (Extension == ".pdf") 
        { 
         Response.ContentType = "application/pdf"; 
        } 
        else 
        { 
         Response.ContentType = "application/vsd-msword"; 
        } 
        Response.AddHeader("content-disposition", "attachment;filename=" + Resume + Extension); 

        Response.Cache.SetCacheability(HttpCacheability.NoCache); 
        Response.BinaryWrite(Attachment);       
        Response.Flush(); 
        Response.End(); 
       } 
       catch (Exception ex) 
       { 
        string str = ex.Message + ex.InnerException; 
       } 
      } 
      else 
      { 
       //ClientScript.RegisterStartupScript(typeof(Page), "SymbolError", "<script type='text/javascript'>alert('Resume is not Uploaded !');</script>"); 
      } 
     } 
    } 
    catch (Exception ex) 
    { 
     string str = ex.Message + ex.InnerException; 

    } 
+0

是你的GridView或更新面板內用戶控件? –

+0

沒有Pawan我沒有使用UpdatePanel,我認爲這個問題從UserControl我創建usrcontrol – SANDEEP

+0

這段代碼工作正常,當我用這個代碼的簡單形式,但在這裏web用戶控制它不工作。 – SANDEEP

回答

0

使用的UpdatePanel,如下圖所示,

<asp:UpdatePanel ID="UpdatePanel1" runat="server"> 
         <ContentTemplate> 
          <asp:LinkButton ID="lnkDownload" runat="server" Text="View" OnClick="lnkDownload_Click" 
           CommandArgument='<%# Eval("Id") %>'></asp:LinkButton> 
         </ContentTemplate> 
         <Triggers> 
          <asp:PostBackTrigger ControlID="lnkDownload" /> 
         </Triggers> 
        </asp:UpdatePanel>