2012-06-13 86 views
0

當我點擊btn控制禁用btn使用JavaScript然後btn單擊事件調用。 裏面的BTN點擊事件我寫的代碼,它給了我在Excel/PDF格式的報告,我使用的方法 ExportToHttpResponse(ExportFormatType.Excel,Response,true,「Report Name」)這給我例外,所以在此方法之後 或finally塊當我寫btn.enable = true;或使用JavaScript,然後不執行。 異常無法評估表達式,因爲代碼已經優化或者本機框架位於調用棧頂部按鈕禁用但不啓用

即我必須在生成報告時啓用btn。 因爲這種方法得到執行ExportToHttpResponse()我得到這個方法,我必須使BTN控制

protected void Page_Load(object sender, EventArgs e) 
{ 
    btnExcel.Attributes.Add("onclick", " this.disabled = true; " + ClientScript.GetPostBackEventReference(btnExcel, null) + ";"); 
} 


protected void btnExcel_Click(object sender, EventArgs e) 
{ 
    view_report(); 
    try 
    { 
     Rpt.ExportToHttpResponse(ExportFormatType.Excel, Response, true, " Reportname"); 
    } 
    catch (Exception ex) 
    { 
     Console.WriteLine(ex.Message); 
     ex = null; 
    } 
    finally 
    {     
     btnExcel.Enabled = true; 
     ScriptManager.RegisterClientScriptBlock(Page, this.GetType(), "CallJSFunction", "myEnablefunction()", true); 
    } 
} 
+0

請包含javascript'myEnablefunction()'的內容。 –

+0

函數myEnablefunction(){btnExcel.disabled = false;} – RakeshKumar

回答

0

如果直接寫入到響應後,所以報告 ,所有的asp.net結構是破產了,所以你不能改變控件的屬性,因爲你已經干涉了asp.net的「自然」渲染。如果在導出過程中出現錯誤,則該頁面已損壞。