`
wangdeshui
  • 浏览: 259104 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

使用ASP.NET 3.5 Extensions管理浏览器历史:使用客户端

阅读更多

1.新建一个web form,代码如下,注意黄色部分

image

2.浏览效果

image

3.贴一个微软提供的示例:

Microsoft sample code
<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><%@ Page Language="C#" %>
<%@ Import Namespace="System.Globalization" %>
<%@ Import Namespace="System.Collections.Generic" %>
<!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 id="Head1" runat="server">
    
<title>Microsoft ASP.NET 3.5 Extensions</title>
    
<link href="http://www.cnblogs.com/include/qsstyle.css" type="text/css" rel="Stylesheet" />

    
<script type="text/javascript">
        
function page_init() {
            Sys.Application.add_navigate(onStateChanged);
            
var cb1 = $get('clientButton1');
            
var cb2 = $get('clientButton2');
            
var cb3 = $get('clientButton3');
            $addHandler(cb1, 
"click", clientClick);
            cb1.dispose 
= function() { $clearHandlers(cb1); }
            $addHandler(cb2, 
"click", clientClick);
            cb2.dispose 
= function() { $clearHandlers(cb2); }
            $addHandler(cb3, 
"click", clientClick);
            cb3.dispose 
= function() { $clearHandlers(cb3); }
        }

        
        
function onStateChanged(sender, e) {
            
// When the page is navigated, this event is raised.
            var val = parseInt(e.get_state().s || '0');
            Sys.Debug.trace(
"Navigated to state " + val);
            $get(
"div2").innerHTML = val;
        }

        
        
function clientClick(e) {
            
// Set a history point in client script.
            var val = parseInt(e.target.value);
            Sys.Application.addHistoryPoint(
{s: val}"Click Button:" + val);
            Sys.Debug.trace(
"History point added: " + val);
       }

    
</script>
</head>
<body>
    
<form id="form1" runat="server">
        
<div>
            
<asp:ScriptManager runat="server" ID="ScriptManager1" EnablePartialRendering="false" EnableHistory="true" />
            
<script type="text/javascript">
                Sys.Application.add_init(page_init);
            
</script>
            
<h2>
                Microsoft ASP.NET 3.5 Extensions: Managing Browser History with Client Script
</h2>
            
</>
            
<div id="Div1" class="new">
                
<p>
                    This sample shows:
</p>
                
<ol>
                    
<li>The <code>Sys.Application</code> object and the <code>navigate</code> event and <code>addHistoryPoint</code> method.</li>
                    
<li>The <code>addHistoryPoint</code> method demonstrates addition of titles.</li>
                
</ol>
            
</div>
            
<p>
            
</p>
            
<h2>Example 1: Managing browser history in client script</h2>
            
<p>This example includes three buttons. The handler for each button's <code>click</code> event sets
            navigation history points using the 
<code>Sys.Application</code> object. The script used here, makes use of the 
            
<code>Sys.Debug</code> class to dump trace information to the TEXTAREA at the bottom of the page. 
            
</p>
            
<p>When you click the buttons, and history points are added, you will be able to see the list of history entries and their titles in the 
            "Recent Pages" drop-down in Internet Explorer, for example.
            
</P>
            
<p>To see history in action, perform the following steps:</p>

            
<ol>
                
<li>Press <b>1</b>. See the trace output.</li>
                
<li>Press <b>3</b>. See the trace output.</li>
                
<li>Press <b>2</b>. See the trace output.</li>
                
<li>Press the browser's Back button. Notice that the page is refreshed with previous data and 
                that trace information shows this.
</li>
            
</ol>
            
<div id="div2" class="box">0</div><p></p>
                
<input type="button" id="clientButton1" value="1" />
                
<input type="button" id="clientButton2" value="2" />
                
<input type="button" id="clientButton3" value="3" />
            
<br /><br />
            
<textarea id="TraceConsole" cols="40" rows="5"></textarea>
        
</div>
    
</form>
</body>
</html>
分享到:
评论

相关推荐

    .net中ajax.net中使用方法

    1. **安装AJAX Extensions**:如果你使用的是.NET Framework 3.5或更低版本,需要安装ASP.NET AJAX Extensions。 2. **启用AJAX支持**:在Visual Studio中创建一个新的ASP.NET Web应用程序时,可以选择"Enable Ajax...

    2.ASP.NET.2.0.高级编程(第4版) [1/7]

    2.ASP.NET.2.0.高级编程(第4版) [1/7] 原书名: Professional ASP.NET 2.0 原出版社: Wrox 作者:(美)Bill Evjen, Scott Hanselman, Farhan Muhammad [同作者作品] [作译者介绍] 译者: 李敏波[同译者作品] ...

    ASP.NET2.0高级编程(第4版)1/6

    本书全面介绍了ASP.NET各种编程技能和2.0版中的巨大变化,并详细阐述了2.0版中的每个新特性。书中提供了大量的实例,可帮助读者快速掌握如何在.NET平台下开发功能强大的ASP.NET应用程序。本书适合有一些基础的ASP...

    AjaxControlToolkit.Binary.NET35

    4. **兼容性**:与ASP.NET AJAX Extensions紧密集成,支持各种浏览器,包括Internet Explorer、Firefox、Chrome等。 5. **自定义行为**:除了控件,还提供了可添加到现有控件上的行为(Behaviors),如...

    Ajax经典教程

    - 为了充分利用 ASP.NET AJAX Extensions 的功能,建议使用 Visual Studio 2008 和 .NET Framework 3.5。 - 注意测试不同浏览器下的兼容性问题。 #### 五、实战演练示例 1. **创建项目**: - 在 Visual Studio ...

    微软Silverlight.3下的3D游戏开发

    在这个例子中,我们使用`Microsoft.Data.Web.dll`集合引用,该引用位于`&lt;符号&gt;Program Files\Reference Assemblies\Microsoft\Framework\ASP.NET 3.5 Extensions`路径下。此外,还需要在代码中引入`Microsoft.Data....

    使用ASP.NET一般处理程序或WebService返回JSON的实现代码

    在.NET 3.5及以上版本中,System.Web.Extensions程序集中包含了System.Web.Script.Serialization命名空间,其中包含了JavaScriptSerializer类,该类提供了对JSON的序列化和反序列化的支持。对于.NET 2.0、3.0版本的...

    AJAX_tutorial04_Localization_cs.pdf

    为开发者带来了许多富客户端功能,例如页面的部分渲染(无需整个页面刷新)、通过客户端脚本访问Web服务(包括ASP.NET剖析API)以及一个旨在模仿ASP.NET服务器控件集合的客户端API。 #### 二、Microsoft AJAX框架中...

Global site tag (gtag.js) - Google Analytics