Welcome Guest Search | Active Topics | Sign In | Register

Lost viewstate on slide menu Options
Mike Wynn
Posted: Thursday, February 14, 2008 9:11:45 AM
Rank: Advanced Member
Groups: Member

Joined: 8/24/2007
Posts: 130
Hi,

I want to use an embedded custom item within a slide menu, and am finding that custom item viewstate is being lost on postback. I have reduced my code to the simple scenario below. If I tick the checkbox and post back, the checked viewstate is lost. I do not have this problem if I use a CustomItem control, however I am databinding the slide menu and custom items dynamically, and it is much better for me to use an embedded custom item via the ITemplate interface. Any suggestions?

Code: HTML/ASPX
<eo:SlideMenu runat="server" ID="clientGroups" EnableViewState="true" ControlSkinID="None"
    SingleExpand="false" Width="100%">
    <TopGroup>
        <Items>
            <eo:MenuItem Text-Html="item">
                <SubMenu>
                    <Items>
                        <eo:MenuItem>
                            <CustomItem>
                                <asp:CheckBox ID="chk" runat="server" />
                            </CustomItem>
                        </eo:MenuItem>
                    </Items>
                </SubMenu>
            </eo:MenuItem>
        </Items>
    </TopGroup>
</eo:SlideMenu>
eo_support
Posted: Thursday, February 14, 2008 10:52:41 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,217
Hi,

Please check the version that you are running. We tested on the latest version and it works fine. Our test code is:

Code: HTML/ASPX
<eo:SlideMenu runat="server" ID="clientGroups" 
    EnableViewState="true" ControlSkinID="None" SingleExpand="false"
    Width="100%">
        <TopGroup>
            <TemplateItem>
                <CustomItem>
                    <asp:CheckBox ID="chk" runat="server" />
                </CustomItem>
            </TemplateItem>
    </TopGroup>
</eo:SlideMenu>
<asp:Button id="Test" runat="server" Text="Button"></asp:Button>


Code: C#
private void Page_Load(object sender, System.EventArgs e)
{
    if (!IsPostBack)
    {
        clientGroups.DataSource = new string[]{"Item 1"};
        clientGroups.DataBind();
    }
}

private void Test_Click(object sender, System.EventArgs e)
{
    CustomItem customItem = clientGroups.Items[0].CustomItemInstance;
    CheckBox checkBox = (CheckBox)customItem.FindControl("chk");
    System.Diagnostics.Debug.WriteLine(checkBox.Checked);
}


Thanks
Mike Wynn
Posted: Friday, February 15, 2008 2:44:51 AM
Rank: Advanced Member
Groups: Member

Joined: 8/24/2007
Posts: 130
Thanks for the reply.

The example you posted works fine, but it does not address my problem. The situation I have, is that I need to bind to a single dimention datasource (IEnumerable). For each Item, I want to create a top level menu item, and a second level item containing a custom item. I have got this to work via code (too much code to post, I'm afraid), but am having the viewstate issue mentioned earlier. The written code renders the html as shown in my example.

Code: HTML/ASPX
<eo:SlideMenu runat="server" ID="clientGroups" EnableViewState="true" ControlSkinID="None"
    SingleExpand="false" Width="100%">
    <TopGroup>
        <Items>
            <eo:MenuItem Text-Html="item">
                <SubMenu>
                    <Items>
                        <eo:MenuItem>
                            <CustomItem>
                                <asp:CheckBox ID="chk" runat="server" />
                            </CustomItem>
                        </eo:MenuItem>
                    </Items>
                </SubMenu>
            </eo:MenuItem>
        </Items>
    </TopGroup>
</eo:SlideMenu>


Please note that this aspx code is different to the code that you posted in your example. When you run this code, then viewstate is lost on postback. I am open to advice on how I may achieve my aim differently.

I have tried specifying a second level custom item template, but can't get this to work.
eo_support
Posted: Friday, February 15, 2008 6:23:29 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,217
Hi,

The most common reason to lose view state during data binding is that DataBind has been either explicitly or implicitly called again. Everytime you call DataBind, the menu (or whatever other controls) wipes out whatever it has and starts over from blank. Consider our sample code, if we don't use if (!PostBack) condition in Page_Load, thus DataBind is called again when the page postbacks, view state would have been lost.

In order to have view state to work correctly, you should only bind once and rely on the menu itself to regenerates everything upon postback. I believe that's the only fundamental difference between your code and our code. So in your case, try to consolidate everything into a single data source and populate the whole menu with one DataBind call. After that it should fall into the same model as our code thus I would expect it to work.

Thanks


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.