• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
我的学习笔记
   首页       联系   管理    订阅  订阅

第九篇: UpdateProgress 控件--用户中断

    有时,当服务器实在运行太久了,我们能否中断它吗?答案是肯定的。

1. 打开第八篇的例子,也就是:UpdateProgress(一).aspx

2. 在 UpdateProgress(一).aspx  的<title></title>
    下面加入一段 Javascript

    <script type="text/javascript">
    function stop()
    {
        
if(Sys.WebForms.PageRequestManager.getInstance().get_isInAsyncPostBack())
        {
            Sys.WebForms.PageRequestManager.getInstance().abortPostBack();
        }
    }
    
</script>


3. UpdateProgress 中添加代码

            <asp:updateprogress ID="UpdateProgress1" runat="server">
                
<progresstemplate>
                    
<span lang="zh-cn">数据正在读取中..请稍后!!!</span>
                    
<input type="button" value ="取消" onclick="stop();" />
                
</progresstemplate>          
            
</asp:updateprogress>


UpdateProgress(一).aspx 代码如下:

Code
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="UpdateProgress(一).aspx.cs" Inherits="UpdateProgress_一_" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    
<title>无标题页</title>
    
<script type="text/javascript">
    function stop()
    {
        
if(Sys.WebForms.PageRequestManager.getInstance().get_isInAsyncPostBack())
        {
            Sys.WebForms.PageRequestManager.getInstance().abortPostBack();
        }
    }
    
</script>
</head>
<body>
    
<form id="form1" runat="server">
    
<div>  
    
<asp:ScriptManager ID="ScriptManager1" runat="server">
    
</asp:ScriptManager>
    
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
        
<ContentTemplate>
            
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
            
<br />
            
<br />
            
<br />
            
<asp:updateprogress ID="UpdateProgress1" runat="server">
                
<progresstemplate>
                    
<span lang="zh-cn">数据正在读取中..请稍后!!!</span>
                    
<input type="button" value ="取消" onclick="stop();" />
                
</progresstemplate>          
            
</asp:updateprogress>
            
<br />
            
<br />
            
<br />
            
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
        
</ContentTemplate>
    
</asp:UpdatePanel>   
    
</div>
    
</form>
</body>
</html>


4. OK. 试试看 ^^

posted @ 2010-01-27 12:08  吴有鋆  阅读(314)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3