2009-07-17 121 views
2

您認爲可以刷新更新面板並在重定向響應後立即(例如下載)?刷新更新面板後重定向

我嘗試這樣做:

  • 一種無形的按鈕 - >作爲 asyncpostbacktrigger

  • 下載 按鈕 - >當它被點擊的OnClientClick點擊無形 按鈕

  • 隱藏按鈕上的點擊事件刷新更新 窗格升
  • 然後下載按鈕點擊 事件啓動下載(正常 回發會啓動下載)

但是由於某些原因,當隱形按鈕被下載按鈕客戶端腳本點擊,它不刷新更新面板..

你知道爲什麼它不起作用嗎? 或者你有其他更清潔的技術?

這裏的元素是如何宣稱:

 <asp:Button runat="server" ID="ButtonInvisible" Text="" Click="RefreshDisplay" /> 

<asp:Button runat="server" ID="ButtonDownload" Text="Download" OnClientClick="clickInvisible(this.id)" Click="Download" /><Triggers> 
       <asp:AsyncPostBackTrigger ControlID="ButtonInvisible" /></Triggers> 

//the javascript 
<script type="text/javascript" language="javascript"> 
function clickInvisible(idButton) { 
    document.getElementById('ButtonInvisible').click(); 

}</script> 

'

//the methods 
Download(object source, EventArgs e){Response.Redirect("test.txt")} 
RefreshDisplay(object source, EventArgs e){ ButtonCancel.Enabled = false;} 

回答

0

是在RefleshDisplay只打算禁用ButtonCancel對接上?然後,你可以做到這一點在普通的JavaScript,而無需使用任何觸發:

<asp:Button runat="server" ID="ButtonDownload" Text="Download" OnClientClick="disableCancelButton()" Click="Download" /> 

<script type="text/javascript" language="javascript"> 
function disableCancelButton() { 
    document.getElementById('<%= ButtonCancel.ClientID %>').disabled = true; 
} 
</script> 
+0

這是真的,但控件的viewstate不會設置爲正確的值。所以在下一個回髮狀態下,這個按鈕會丟失。 – teebot 2009-07-17 12:01:53

0

我也有過類似的問題,並通過使用hidden IFRAME trick解決它。不需要隱形按鈕。事實上,我的版本甚至不需要JavaScript:

protected void Button1_Click(object sender, EventArgs e) 
{ 
    // update some controls in the UpdatePanel 
    ... 

    // add an iframe which will start the download at the bottom of the UpdatePanel 
    var iframe = new HtmlGenericControl("iframe"); 
    iframe.Style["display"] = "none"; 
    iframe.Attributes["src"] = "http://...download url..."; 
    iframe.EnableViewState = false  // we only need the iframe for this one postback 
    myUpdatePanel.ContentTemplateContainer.Controls.Add(iframe) 
}