刷新更新面板后重定向

发布于 2024-07-27 17:10:26 字数 1172 浏览 3 评论 0原文

您认为可以在重定向响应(例如下载)后立即刷新更新面板吗?

我尝试了这个:

  • 一个隐形按钮 -> 作为 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;}

Do you think it's possible to refresh an update panel and immediately after redirecting the response (for instance a download) ?

I tried this:

  • an invisible button -> as an
    asyncpostbacktrigger

  • a download
    button -> when it is clicked the
    onclientclick clicks the invisible
    button

  • the click event on the
    invisible button refreshes the update
    panel
  • then the download button click
    event launches the download (normal
    postback which launches the download)

However for some reason when the invisible button is clicked by the download button client script, it doesn't refresh the update panel..

Do you have an idea why it doesn't work?
Or do you have other and cleaner techniques?

Here's how the elements are declared:

     <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;}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

醉殇 2024-08-03 17:10:26

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>

Is the RefleshDisplay only going to disable the ButtonCancel button? Then you can do it in plain JavaScript without using any trigger:

<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>
喵星人汪星人 2024-08-03 17:10:26

我遇到了类似的问题,并通过使用隐藏的 IFRAME 技巧解决了它。 不需要隐形按钮。 事实上,我的版本甚至不需要 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)
}

I have had a similar problem and solved it by using the hidden IFRAME trick. No invisible button required. In fact, my version does not even require 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)
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文