2009-07-17 151 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) 
}