PDA

View Full Version : [CLOSED] Split Button Menu add Item dynamicaly



xtoolz
Jul 21, 2015, 12:37 PM
Hi all

I need to add Split Button Menu Items dynamically.

I try to add Items to this Split Button :


<ext:SplitButton runat="server" ID="DocumentSplitButton" Icon="PageMagnify">
<Menu>
<ext:Menu runat="server">

</ext:Menu>
</Menu>
</ext:SplitButton>

Here's my Code :


DocumentSplitButton.Menu(0).Items.Clear()

Dim docs = ServiceClient.GetDocumentsById(id)
For Each doc As Document In docs
DocumentSplitButton.Menu(0).Items.Add(New MenuItem() With {.Text = doc.DisplayName})
Next

The Items seems to be existent during debug but they aren't rendered ?!
To I miss an update call ?

Kind Regards
Peter

xtoolz
Jul 21, 2015, 2:59 PM
OK, in the meanwhile adding a Menu Item works ! But I face now a new Problem :-/
While clicking on the Menu Item this Error occures :

The control with ID 'DocumentPreviewItem_2d579e80-a01c-45cc-9dc2-63d1de7cbde0' not found



My Code looks like that


DocumentSplitButton.Menu(0).RemoveAll()

Dim mi As MenuItem

For Each doc As Document In ServiceClient.GetDocumentsById(Guid.Parse(id))

mi = New MenuItem() With {.Text = doc.DisplayName, .Icon = Ext.Net.Icon.PageWhiteAcrobat, .ID = String.Format("DocumentPreviewItem_{0}", doc.Id.ToString)}

AddHandler mi.DirectEvents.Click.Event, AddressOf ShowPreViewWindow
mi.DirectEvents.Click.ExtraParams.Add((New Ext.Net.Parameter() With {.Value = doc.Id.ToString, .Name = "id", .Mode = ParameterMode.Value}))

mi.AddTo(DocumentSplitButton.Menu(0))

Form.Controls.Add(mi)
Next

Any Help is welcome :-)

Daniil
Jul 21, 2015, 4:10 PM
Hi Peter,

I think you are facing the same problem that has been discussed in these threads (and many others).
http://forums.ext.net/showthread.php?23980&p=105183&viewfull=1#post105183
http://forums.ext.net/showthread.php?14316&p=60155&viewfull=1#post60155

You create a dynamic control and attach a DirectEvent to that control, but don't recreate the control when the DirectEvent fires. But DirectEvent requires a control instance on server. You can recreate the dynamic control or use DirectMethods instead.

xtoolz
Jul 22, 2015, 1:44 PM
Hi Daniil

the Listener works perfect, thanks for the help !

Peter