首页 新闻 会员 周边

在AJAX中怎样实现调用后台方法AA()?

0
悬赏园豆:10 [已解决问题] 解决于 2010-08-10 15:46

<asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>   
               
                <asp:Timer ID="Timer1" runat="server" Interval = "1000"></asp:Timer>  
          <asp:UpdateProgress ID="UpdateProgress1" runat="server">
                <ProgressTemplate >
                图片读取中......
                </ProgressTemplate>
                </asp:UpdateProgress>
            </ContentTemplate>
        </asp:UpdatePanel>

在每次定时刷新后,希望调用后台的AA(),怎样实现?

女孩的主页 女孩 | 初学一级 | 园豆:170
提问于:2010-08-10 08:38
< >
分享
最佳答案
0

直接为timer绑定触发的方法即可。

protected void Timer1_Tick(object sender, EventArgs e)
{
//方法体
}

调用AA()的话。在这个触发的方法里面调用吧。

 

收获园豆:4
邢少 | 专家六级 |园豆:10926 | 2010-08-10 08:45
如果你的AA方法是注册一段脚本的话,可能有问题。因为注册脚本的方法不同,脚本注册的位置不同。比必须要把脚本注册到你的updatepanel中才可以弹出提示框。 在使用updatepanel的页面中注册脚本应该是注册到scriptManager中。 ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "a", "alert('没有找到数据');", true); page.ClientScript.RegisterStartupScript 是不行的。
邢少 | 园豆:10926 (专家六级) | 2010-08-10 11:23
你弹出提示框是测试的是吧。 你完全可以在那个updatepanel中添加一个<lable>或者是textbox。来接收你定时执行的结果信息。因为updatepanel局部刷新控件。只刷新范围内的内容,你注册脚本也好。改变值也好,必须在updatepanel范围内。
邢少 | 园豆:10926 (专家六级) | 2010-08-10 11:26
其他回答(2)
0

protected void Timer1_Tick(object sender, EventArgs e)
{
AA();
}
public void AA()
{
}

 


 

收获园豆:3
jowo | 园豆:2834 (老鸟四级) | 2010-08-10 08:55
0
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Timer ID="Timer1" runat="server" Interval="1000" OnTick="Timer1_Tick">
</asp:Timer>
</ContentTemplate>
</asp:UpdatePanel>

 

后台代码


protected void Timer1_Tick(object sender, EventArgs e)
{
aa();
}

public void aa() {
ScriptManager.RegisterStartupScript(
this, this.GetType(), "js", "alert('11');", true);
}
收获园豆:3
廖雪萍 | 园豆:88 (初学一级) | 2010-08-10 11:24
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册