views:

82

answers:

2

Hello,

I'm getting some strange behaviour with viewstate being lost on postback for a .net application using Sitecore. I'm assuming it might be some config variable somewhere but I'm new to Sitecore and don't really know where to start looking.


UPDATE: Sitecore has now gotten back to us with an answer. We had recently added the dtSearch module, and AutomaticDataBind was set to true in the dtSearch.config which overrides the setting in the web config. We've now removed it and it works fine again.


I've made a mini test if that might help. It's two usercontrols on one page, both with a repeater. When updating the viewstate gets lost so even if I'm binding the updated repeater again the data for the other one will be lost.

Usercontrol 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;
}

Usercontrol 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();
 }
}

Does anyone have any ideas what might be going on? Let me know if I need to provide any more information. The most annoying thing is that it was working last week but I have no idea what has changed!

Thanks,

Annelie

A: 

Do you have System.Web.UI.WebControls.Repeater in the "typesThatShouldNotBeExpanded" section of your web.config?

I've found that there are definitely some things that don't work with the regular PostBack model in Sitecore... but this Repeater should be OK.

One trouble area is having FieldRenderers inside Repeaters. They don't seem to restore the Item property correctly on Postback.

Bryan
What Brian said. Is almost certainly a typesThatShouldNotBeExpanded related issue. References: http://intothecore.cassidy.dk/2009/01/typesthatshouldnotbeexpanded.html and http://sdn.sitecore.net/Scrapbook/ListView%20and%20DataPager%20under%20Sitecore%20context.aspx
Mark Cassidy
Sitecore 6.3 adds the following setting: <typesThatShouldNotBeExpanded> <type>System.Web.UI.WebControls.Repeater</type> <type>System.Web.UI.WebControls.DataList</type> <type>System.Web.UI.WebControls.GridView</type> <type>System.Web.UI.WebControls.ListView</type> <type>System.Web.UI.WebControls.FormView</type> <type>Microsoft.Reporting.WebForms.ReportViewer</type> <type>Telerik.Web.UI.RadGrid</type> </typesThatShouldNotBeExpanded>
Mark Cassidy
Repeater and Datalist are already in there so don't think that's the issue unfortunately.
annelie
Make sure you have all caching settings turned off at the Sublayout AND Presentation Details level as well.
Bryan
@Bryan - As far as I can tell they're turned off. One of the other guys did a simple test on a page and that didn't work either, so the same thing happens even when it's not a sublayout. Seems like there must be some global setting somewhere but don't know what. We're sending the whole project to Sitecore today so they can have a look, I'll post what they say once they get back to us. If we don't find it before they do that is. :)
annelie
A: 

As far as I can see, this thread describes exactly the same problem, but with DataGrid. See if setting AutomaticDataBind to 'false' in web.config helps.

Yan Sklyarenko
Thanks for the link, however it's already set to false so must be something else going on.
annelie