【问题标题】:Viewstate lost on postback for .net Sitecore page.net Sitecore 页面的回发时 Viewstate 丢失
【发布时间】:2010-10-27 16:13:15
【问题描述】:

我遇到了一些奇怪的行为,即使用 Sitecore 的 .net 应用程序在回发时丢失了视图状态。我假设它可能是某个地方的一些配置变量,但我是 Sitecore 的新手,真的不知道从哪里开始寻找。


更新: Sitecore 现已回复我们并提供了答复。我们最近添加了 dtSearch 模块,并且 AutomaticDataBind 在 dtSearch.config 中设置为 true,它会覆盖 Web 配置中的设置。我们现在已将其删除,它再次正常工作。


如果有帮助,我已经做了一个小测试。它是一页上的两个用户控件,都带有一个中继器。更新视图状态时会丢失,因此即使我再次绑定更新的转发器,另一个的数据也会丢失。

用户控件 1:

<asp:Repeater runat="server" ID="Repeater1" OnItemDataBound="Repeater1_ItemBind">
 <ItemTemplate>
  <li>
   <asp:Literal runat="server" ID="Literal1"></asp:Literal>
  </li>
 </ItemTemplate>
</asp:Repeater>
protected void Page_Load(object sender, EventArgs e)
{
 if (!IsPostBack)
 {
  List<string> myTestList1 = new List<string>();
  myTestList1.Add("a");
  myTestList1.Add("b");

  Repeater1.DataSource = myTestList1;
  Repeater1.DataBind();
 }
}

protected void Repeater1_ItemBind(object sender, RepeaterItemEventArgs e)
{
 Literal Literal1 = (Literal)e.Item.FindControl("Literal1");
 Literal1.Text = (string)e.Item.DataItem;
}

用户控件 2:

<asp:Repeater runat="server" ID="Repeater2" OnItemDataBound="Repeater2_ItemBind" OnItemCommand="Repeater2_Command">
 <ItemTemplate>
  <li>
   <asp:Literal runat="server" ID="Literal2"></asp:Literal>

   <asp:LinkButton ID="Update" CommandName="Update" runat="server">
    update
   </asp:LinkButton>
  </li>
 </ItemTemplate>
</asp:Repeater>
private string test = String.Empty;

protected void Page_Load(object sender, EventArgs e)
{
 if (!IsPostBack)
 {
  test = "a";

  Repeater2.DataSource = test;
  Repeater2.DataBind();
 }
}

protected void Repeater2_ItemBind(object sender, RepeaterItemEventArgs e)
{
 char c = (char)e.Item.DataItem;

 Literal Literal2 = (Literal)e.Item.FindControl("Literal2");
 Literal2.Text = c.ToString();
}


protected void Repeater2_Command(object sender, RepeaterCommandEventArgs e)
{
 if (e.CommandName == "Update")
 {
  test = "b";

  Repeater2.DataSource = test;
  Repeater2.DataBind();
 }
}

有人知道会发生什么吗?如果我需要提供更多信息,请告诉我。最烦的是上周还在工作,但我不知道发生了什么变化!

谢谢,

安妮

【问题讨论】:

    标签: asp.net viewstate sitecore


    【解决方案1】:

    您的 web.config 的“typesThatShouldNotBeExpanded”部分中是否有 System.Web.UI.WebControls.Repeater?

    我发现Sitecore 中的常规PostBack 模型肯定有一些东西无法使用......但是这个Repeater 应该没问题。

    一个麻烦的地方是在中继器内部有 FieldRenderer。他们似乎没有在 Postback 上正确恢复 Item 属性。

    【讨论】:

    • 布莱恩所说的。几乎可以肯定是与 typesThatShouldNotBeExpanded 相关的问题。参考:intothecore.cassidy.dk/2009/01/…sdn.sitecore.net/Scrapbook/…
    • Sitecore 6.3 添加了以下设置:System.Web.UI.WebControls.RepeaterSystem.Web.UI.WebControls.DataListSystem.Web.UI.WebControls.GridViewSystem.Web.UI.WebControls.ListViewSystem.Web.UI.WebControls.FormViewMicrosoft.Reporting.WebForms.ReportViewerTelerik.Web.UI.RadGrid
    • Repeater 和 Datalist 已经在其中,所以不要认为这是问题所在。
    • 确保您在子布局和演示详细信息级别也关闭了所有缓存设置。
    • 据我所知,它们已关闭。其他人中的一个人在页面上做了一个简单的测试,但也没有用,所以即使它不是子布局,也会发生同样的事情。似乎某处必须有一些全局设置,但不知道是什么。我们今天将整个项目发送到 Sitecore,以便他们查看,一旦他们回复我们,我会发布他们所说的内容。如果我们在他们这样做之前没有找到它。 :)
    【解决方案2】:

    据我所知,this thread 描述了完全相同的问题,但使用的是 DataGrid。看看在 web.config 中将 AutomaticDataBind 设置为 'false' 是否有帮助。

    【讨论】:

    • 感谢您的链接,但它已经设置为 false,所以一定是其他事情。
    • @Yan - 查看更新,在 dtSearch.config 中将 AutomaticDataBind 设置为 true,它会覆盖 Web 配置中的设置。
    • @annelie:太好了,事实证明这正是来源完全已知的问题;-)
    • @Yan - 我并不完全了解它。 :) 我不知道他们正在修补配置,我会假设额外的配置只会更改与该模块相关的值而不覆盖主要的值,但是您每天都会学到新的东西! :)
    • @annelie - 哦,那你一定要熟悉sdn.sitecore.net/FAQ/Administration/…intothecore.cassidy.dk/2009/05/…。祝你好运! :-)
    猜你喜欢
    • 1970-01-01
    • 2018-05-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多