部分回发使用Javascript [英] Partial postback with Javascript

查看:123
本文介绍了部分回发使用Javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法找到如此相似的东西。

I couldn't find something similar in SO.

在ASP.NET中,有没有什么办法,在暗示我可能会导致与JavaScript的一个部分回发在一个UpdatePanel?
我试过 __ doPostBack()但它完全回发。
我可以用一个虚拟的按钮和消防点击()再处理局部回传这样欺骗,但我想不是挂羊头卖狗肉更优雅的方式。

In ASP.NET, is there any way that on cue I can cause a partial postback with Javascript in an UpdatePanel?
I tried __doPostBack() but it does a full postback.
I can trick it with a dummy button and fire click() then handle the partial postback that way, but I want a more graceful way than trickery.

感谢。

编辑:我发现这个<一href="http://disturbedbuddha.word$p$pss.com/2007/11/26/">disturbedbuddha.word$p$pss.com/2007/11/26/…但我不能让它的工作=(
我喜欢这种方法工作;很适合我! 到目前为止,我用这最后的方法可以做的是增益参考定时器。随着计时开始禁用,启动定时器似乎并没有引起回发。然而,如果没有Ajax的,如果我只是有计时器开始启用,这回发的时间间隔就好了;为什么不能Ajax调用造成的吗?

I found this disturbedbuddha.wordpress.com/2007/11/26/… but I can't get it to work =(
I would love for this method to work; it's perfect for me! So far what I can do using this last method is gain reference to the timer. With the timer initially disabled, starting the timer doesn't seem to cause a postback. However, without Ajax, if I simply have the timer enabled initially, it posts back at intervals just fine; why can't the Ajax call cause it?

推荐答案

您可以使用AsyncPostBackTrigger与UpdatePanel的做到这一点。因为你需要的东西,可以触发一个事件,用一个按钮是相当简单,时隐时现的作品很好。

You can use an AsyncPostBackTrigger with the UpdatePanel to do this. Because you need something that can fire an event, using a button is fairly simple and when hidden works nicely.

如果这是你的标记:

<asp:UpdatePanel ID="UpdatePanel1" runat="server" OnLoad="UpdatePanel1_Load">
    <ContentTemplate>
        <!-- Contents... -->
    </ContentTemplate>
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="ReloadThePanel" EventName="Click" />
    </Triggers>
</asp:UpdatePanel>
<asp:Button ID="ReloadThePanel" runat="server" style="display:none;" />

在您需要的面板进行更新,你只需要调用:

When you want the panel to be updated, you just need to call:

__doPostBack('<%=ReloadThePanel.ClientID %>', null);

这会使ASP.NET认为ReloadThePanel被点击以及JavaScript自动生成的,由于触发器将处理其余部分。

This will make ASP.NET think that ReloadThePanel was clicked and the JavaScript auto-generated due to the trigger will handle the rest.

修改

您可以做的UpdatePanel的纯JavaScript的更新没有任何触发器或隐藏的按钮。你只需要调用 __ doPostBack 与客户端ID作为第一个参数。

You can do a pure JavaScript update of the UpdatePanel without any triggers or hidden buttons. You just need to invoke __doPostBack with the client-side ID as the first argument.

__doPostBack('<%=UpdatePanel1.ClientID %>', null);

这篇关于部分回发使用Javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆