PDA

View Full Version : [CLOSED] Update CycleButton MenuItems in DirectEvent



prost
May 07, 2013, 12:54 PM
Hi,
I would like to update the menuitems of a CycleButton during a directevent. This seems to work only parial, the new items are added to the menu, but the active/checked item is not set (the initial menu item is still the selected). Also the cycle functionality does not work.
Hope you can help, thnx,
Sander

Ext.NET version: 2.2.0.21675
Tested with Chrome & IE8



<%@ Page Language="C#" %>


<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>


<!DOCTYPE html>


<script runat="server">


public void OnTstBtnClick(object sender, DirectEventArgs e)
{
CycleButton1.Menu[0].RemoveAll();


var mi = new CheckMenuItem
{
ID = "cmi1",
Text = "cmi1",
Icon = Icon.World,
};


CycleButton1.Menu[0].Items.Add(mi);
mi.Render();

mi = new CheckMenuItem
{
ID = "cmi2",
Text = "cmi2",
Icon = Icon.Accept,
Checked = true
};


CycleButton1.Menu[0].Items.Add(mi);
mi.Render();


CycleButton1.Menu[0].ActiveIndex = 1;
}

</script>


<html>
<head id="Head1" runat="server">
<title>CycleButton test</title>
</head>
<body>
<form id="Form1" runat="server">
<ext:ResourceManager ID="ResourceManager1" runat="server" />
<ext:FormPanel ID="formPanel" runat="server"
Width="400"
Height="200"
Title="CycleButton menu update test">
<Items>
<ext:CycleButton ID="CycleButton1" runat="server" ShowText="true" PrependText="View As ">
<Menu>
<ext:Menu ID="Menu1" runat="server">
<Items>
<ext:CheckMenuItem ID="CheckMenuItem1" runat="server" Text="Text Only" Icon="Note" />
<ext:CheckMenuItem ID="CheckMenuItem2" runat="server" Text="Html" Icon="Html" Checked="true" />
</Items>
</ext:Menu>
</Menu>
</ext:CycleButton>
</Items>
<Buttons>
<ext:Button ID="tstBtn" runat="server" Text="Change menu items">
<DirectEvents>
<Click OnEvent="OnTstBtnClick" />
</DirectEvents>
</ext:Button>
</Buttons>
</ext:FormPanel>
</form>
</body>
</html>

Daniil
May 07, 2013, 4:57 PM
Hi Sander,

During its life cycle (the initComponent method) a CycleButton puts its own logic on each menu item. It is not enough to render a new menu item. It needs to re-render a CycleButton itself after adding new items to its menu.

prost
May 08, 2013, 2:39 PM
Hi Daniil,
I already tried to update the button itself (using CycleButton1.Render();), but it results in Javascript exceptions when clicking the button.
Can you modify my example in something that works?
Thanks!
Sander

Daniil
May 08, 2013, 4:18 PM
This appears to be working.


public void OnTstBtnClick(object sender, DirectEventArgs e)
{
CycleButton1.Menu[0].Items.Clear();

var mi = new CheckMenuItem
{
ID = "cmi1",
Text = "cmi1",
Icon = Icon.World,
};
CycleButton1.Menu[0].Items.Add(mi);

mi = new CheckMenuItem
{
ID = "cmi2",
Text = "cmi2",
Icon = Icon.Accept,
Checked = true
};
CycleButton1.Menu[0].Items.Add(mi);

CycleButton1.Render();
}

prost
May 08, 2013, 5:10 PM
Hi Daniil, you're right, it works! Must have been doing something wrong.....
Thanks!