C# 如何在多视图中注册历史记录条目(后退/前进)(在活动索引更改时)

C# 如何在多视图中注册历史记录条目(后退/前进)(在活动索引更改时),c#,asp.net,ajax,scriptmanager,multiview,C#,Asp.net,Ajax,Scriptmanager,Multiview,我正在使用更新面板异步更新我的部分页面。当多视图更改其活动索引时,需要注册其导航 例如,当页面首次加载时,多视图活动索引=0。 当用户单击链接时,我显示视图索引1的内容 允许用户使用浏览器历史记录进行前后移动非常重要 ScriptManager位于母版页中,其EnableHistory属性设置为True 有人在使用Multiview时实现了它吗?我认为这应该可以,但您需要对它进行一些自定义。我正在做一些非常类似的事情,但是我不得不放弃在updatepanel中使用multview,因为我在其中嵌

我正在使用更新面板异步更新我的部分页面。当多视图更改其活动索引时,需要注册其导航

例如,当页面首次加载时,多视图活动索引=0。 当用户单击链接时,我显示视图索引1的内容

允许用户使用浏览器历史记录进行前后移动非常重要

ScriptManager
位于母版页中,其
EnableHistory
属性设置为
True


有人在使用Multiview时实现了它吗?

我认为这应该可以,但您需要对它进行一些自定义。我正在做一些非常类似的事情,但是我不得不放弃在updatepanel中使用multview,因为我在其中嵌入的第三方控件有问题

您需要使用下面的asp.net标记在aspx文件中添加对母版页的引用。另外,在母版页中将scriptmanager公开为公共控件,以便将事件关联到它

在页面的设计/html代码中:将虚拟路径更新到主控形状或使用类型分配类型引用

<%@ MasterType VirtualPath="~/MasterPage.master" %>
然后在页面的加载事件中:

protected void Page_Load(object sender, EventArgs e)
{              
    this.Master.ScriptManager.Navigate += 
    new EventHandler<HistoryEventArgs>(ScriptManager_Navigate);

    if (!this.IsPostBack && !ScriptManager.GetCurrent(this).IsInAsyncPostBack)
    {
        // load default multiview index
    }           
}
args将是多视图索引。这些只是我使用的辅助函数。如果索引是您唯一关心的项,那么您可以将这些调用内联到main方法

private void SetMyArgs(string args)
{
    int myIndex = int.Parse(args);
    // set multiview index here?
}

private string GetMyArgs()
{
    return myMultiview.ActiveIndex.ToString();
}
然后,当您触发更改活动索引的事件时,将其添加到这些方法中

if (this.IsAsync)
{
    this.Master.ScriptManager.AddHistoryPoint("myArgs", GetMyArgs());
}

希望这能给你一些帮助

您不应该使用
this.IsAsync
而是
ScriptManager.GetCurrent(第页).IsInAsyncPostBack
(或者在您的情况下,
this.Master.ScriptManager.IsInAsyncPostBack
)。

嗨,Jim,非常感谢,它现在正以应有的方式工作!乔西
private void SetMyArgs(string args)
{
    int myIndex = int.Parse(args);
    // set multiview index here?
}

private string GetMyArgs()
{
    return myMultiview.ActiveIndex.ToString();
}
if (this.IsAsync)
{
    this.Master.ScriptManager.AddHistoryPoint("myArgs", GetMyArgs());
}