我正在使用更新面板来异步更新我的部分页面。当多视图更改其活动索引时,需要注册其导航。
例如,第一次加载页面时,Multiview Active Index = 0。当用户单击链接时,我显示 View index 1 的内容。
允许用户使用浏览器历史记录前后移动非常重要。
位于ScriptManager母版页中,其EnableHistory属性设置为True。
有人在使用 Multiview 时实现了它吗?
我正在使用更新面板来异步更新我的部分页面。当多视图更改其活动索引时,需要注册其导航。
例如,第一次加载页面时,Multiview Active Index = 0。当用户单击链接时,我显示 View index 1 的内容。
允许用户使用浏览器历史记录前后移动非常重要。
位于ScriptManager母版页中,其EnableHistory属性设置为True。
有人在使用 Multiview 时实现了它吗?
我认为这应该可以,但是您需要对其进行一些自定义。我正在做一些非常相似的事情,但是由于我嵌入其中的第三方控件存在问题,我不得不放弃在更新面板中使用多视图。
您需要使用下面的 asp.net 标记在您的 aspx 文件中添加对母版页的引用。此外,将脚本管理器公开为母版页中的公共控件,以便您可以将事件连接到它。
在页面的设计/html 代码中:更新 Master 的虚拟路径或使用 Type 来分配类型引用。
<%@ MasterType VirtualPath="~/MasterPage.master" %>
在您页面的初始化事件中:
public void Page_Init(object sender, EventArgs e)
{
// can be done at MasterPage level if you like
this.Master.ScriptManager.EnableHistory = true;
}
然后在页面的加载事件中:
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
}
}
然后将此新事件处理程序添加到您的页面。这将项目命名为“myArgs”,您应该为您的内容使用更直观的东西。在我的实现中,我有一系列项目(如排序顺序、页面索引等,由分隔符分隔,然后将它们分解并分配它们)。
protected void ScriptManager_Navigate(object sender, HistoryEventArgs e)
{
if (!string.IsNullOrEmpty(e.State["myArgs"]))
{
string args = e.State["myArgs"];
SetMyArgs(args);
}
else
{
// just load default
}
}
args 将是多视图索引。这些只是我使用的辅助函数。如果 index 是您唯一关心的项目,那么您可以将这些调用内联到主要方法。
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.IsAsyncbut
ScriptManager.GetCurrent(Page).IsInAsyncPostBack(或者在您的情况下,this.Master.ScriptManager.IsInAsyncPostBack)。