刷新更新面板后重定向
您认为可以在重定向响应(例如下载)后立即刷新更新面板吗?
我尝试了这个:
一个隐形按钮 -> 作为 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
asyncpostbacktriggera 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
RefleshDisplay
是否只会禁用 ButtonCancel 按钮? 然后你可以用纯 JavaScript 来完成它,而不使用任何触发器:Is the
RefleshDisplay
only going to disable the ButtonCancel button? Then you can do it in plain JavaScript without using any trigger:我遇到了类似的问题,并通过使用隐藏的 IFRAME 技巧解决了它。 不需要隐形按钮。 事实上,我的版本甚至不需要 JavaScript:
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: