Problem with Per Item Template and OnClick Events

3 posts, 1 answers
  1. Peter
    Peter avatar
    39 posts
    Member since:
    Jul 2012

    Posted 16 Nov 2012 Link to this post

    hi

    i am trying to use the radmenu with peritem templates as i want some specific functionality there , i saw several of your demos where you had buttons etc inside a menu item , and they had Server OnClick events attached to them.

    when i set up the menu with the template , it gives me no option to access the controls on the server side , or even attach an event to it , 
    this is a rough copy of the menu , but on the server side i cannot access any of the controls in it .

    <telerik:RadMenu ID="RadMenu1" runat="server" Height="30px" Skin="WebBlue" Width="100%"
                ClientIDMode="AutoID">
                <Items>
                    <telerik:RadMenuItem runat="server" AccessKey="M" Text="My Dashboards">
                    </telerik:RadMenuItem>
                    <telerik:RadMenuItem runat="server" Text="Edit">
                        <Items>
                            <telerik:RadMenuItem Text="Rename dashboard" AccessKey="S" PostBack="true" />
                            <telerik:RadMenuItem Text="Set as default dashboard" AccessKey="R" PostBack="true" />
                            <telerik:RadMenuItem Text="Delete current dashboard" AccessKey="D" PostBack="true" />
                            <telerik:RadMenuItem Text="Delete multiple dashboards" runat="server">
                                <GroupSettings Height="600px" Flow="Vertical"></GroupSettings>
                                <Items>
                                    <telerik:RadMenuItem CssClass="rmItemE" runat="server">
                                        <ItemTemplate>
                                            <asp:CheckBoxList ID="DeleteDash" runat="server">
                                            </asp:CheckBoxList>
                                            <asp:Button runat="server" OnClientClick="if(!confirm('Are you certain you want to delete?')){return false;}"
                                                Text="Delete selected" ID="deleteseldbs" />
                                        </ItemTemplate>
                                    </telerik:RadMenuItem>
                                </Items>
                            </telerik:RadMenuItem>
                            <telerik:RadMenuItem Text="Share dashboard" AccessKey="W" />
                            <telerik:RadMenuItem Text="Print selected charts" AccessKey="o">
                                <Items>
                                    <telerik:RadMenuItem Text="1 chart on each page" Value="1">
                                        <Items>
                                            <telerik:RadMenuItem CssClass="rmItemE">
                                                <ItemTemplate>
                                                    <asp:CheckBoxList runat="server" ID="pdfmentexts">
                                                        <asp:ListItem Text="Caption" Value="C"></asp:ListItem>
                                                        <asp:ListItem Text="Private note" Value="P"></asp:ListItem>
                                                        <asp:ListItem Text="Shared note" Value="S"></asp:ListItem>
                                                    </asp:CheckBoxList>
                                                    <asp:Button ID="Button6" runat="server" Text="Create pdf" />
                                                </ItemTemplate>
                                            </telerik:RadMenuItem>
                                        </Items>
                                    </telerik:RadMenuItem>
                                    <telerik:RadMenuItem Text="2 charts on each page" Value="2">
                                        <Items>
                                            <telerik:RadMenuItem CssClass="rmItemE">
                                                <ItemTemplate>
                                                    <asp:CheckBoxList ID="CheckBoxList1" runat="server">
                                                        <asp:ListItem Text="Caption" Value="C"></asp:ListItem>
                                                        <asp:ListItem Text="Private note" Value="P"></asp:ListItem>
                                                        <asp:ListItem Text="Shared note" Value="S"></asp:ListItem>
                                                    </asp:CheckBoxList>
                                                    <asp:Button ID="Button2_pdf" runat="server" Text="Create pdf" />
                                                </ItemTemplate>
                                            </telerik:RadMenuItem>
                                        </Items>
                                    </telerik:RadMenuItem>
                                    <telerik:RadMenuItem Text="4 charts on each page" Value="4">
                                        <Items>
                                            <telerik:RadMenuItem CssClass="rmItemE">
                                                <ItemTemplate>
                                                    <asp:CheckBoxList ID="CheckBoxList2" runat="server">
                                                        <asp:ListItem Text="Caption" Value="C"></asp:ListItem>
                                                        <asp:ListItem Text="Private note" Value="P"></asp:ListItem>
                                                        <asp:ListItem Text="Shared note" Value="S"></asp:ListItem>
                                                    </asp:CheckBoxList>
                                                    <telerik:RadButton ID="btnCreatePDF" runat="server" Text="Create pdf" EnableBrowserButtonStyle="True"
                                                        OnClick="btnCreatePDF_Click">
                                                    </telerik:RadButton>
                                                </ItemTemplate>
                                            </telerik:RadMenuItem>
                                        </Items>
                                    </telerik:RadMenuItem>
                                </Items>
                            </telerik:RadMenuItem>
                            <telerik:RadMenuItem Text="Export selected to PowerPoint" AccessKey="i">
                                <Items>
                                    <telerik:RadMenuItem Text="1 chart on each page" Value="1" />
                                </Items>
                            </telerik:RadMenuItem>
                            <telerik:RadMenuItem Text="Copy this dashboard" AccessKey="M" />
                            <telerik:RadMenuItem Text="MultiCopy dashboards" AccessKey="G" />
                            <telerik:RadMenuItem Text="Select all items" AccessKey="C" />
                            <telerik:RadMenuItem Text="Link to this dashboard" />
                        </Items>
                    </telerik:RadMenuItem>
                    <telerik:RadMenuItem runat="server" Text="Shared Dashboards">
                    </telerik:RadMenuItem>
                    <telerik:RadMenuItem runat="server" Text="Back to main Menu" NavigateUrl="Default.aspx">
                    </telerik:RadMenuItem>
                    <telerik:RadMenuItem runat="server" Text="Current Dashboard :" Width="400px">
                    </telerik:RadMenuItem>
                    <telerik:RadMenuItem runat="server" Text="Logged in as :">
                    </telerik:RadMenuItem>
                </Items>
            </telerik:RadMenu>
  2. Peter
    Peter avatar
    39 posts
    Member since:
    Jul 2012

    Posted 16 Nov 2012 Link to this post

    sorry just to clarify , the issue i have is that i want to be able to access the controls in the item template at run time to be able to populate with values or change things , is this at all possible ?
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 18 Nov 2012 Link to this post

    Hi,

    You can access the controls from server side as shown below.
    C#:
    protected void RadMenu1_ItemClick(object sender, RadMenuEventArgs e)
    {
        RadMenuItem item = RadMenu1.FindItemByText("text");
        TextBox txt = (TextBox)item.FindControl("TextBox1");
    }

    Thanks,
    Princy.
Back to Top