hard problem

  1. #1

    hard problem

    hello everybody , i need from any one of you , to create a menu and to add some menu items in them , then try to override the findcontrol method
    put a break point on that method , then try to click any menu item in coolite

    it will have an id of "submitAjaxEventConfig" or something like that whereas in normal asp.net controls the id becomes the clicked item

    any suggestions
  2. #2

    RE: hard problem

    Hi snoutoz,

    Please post a simplified .aspx code sample demonstrating the scenario and how to reproduce the problem. Without a simplified code sample that we can single copy/paste, the coolite support team will be unable to provide assistence based on just the description of your issue.*




    Geoffrey McGill
    Founder
  3. #3

    RE: hard problem

    My friend , it doesn't need a source file , i tell you to open a new solution add two or more menu items to a tool bar

    inside the default.aspx.cs file try to override method "findControl (string id)" like the following


    
    protected override FindControl ( string id)
    {
        return base.FindControl(id);
    }

    put a break point at the current method , then initialize the debug

    once you click on any menu item , it will hang on to the current findcontrol method , then have a look at the id parameter value

    it will always be "submitAjaxEventConfig" string value , whatever the control pressed was

    here is a simplified .aspx source code

    
    <%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>
    
    <%@ Register Assembly="Coolite.Ext.Web" Namespace="Coolite.Ext.Web" TagPrefix="ext" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Untitled Page</title>
    </head>
    <body>
        <form id="form1" runat="server">
        
            <ext:ScriptManager ID="ScriptManager1" runat="server">
            </ext:ScriptManager>
            
            <ext:Toolbar ID="MainToolBar" runat="server">
            <Items>
            <ext:ToolbarButton ID="Button1" runat="server" Text="File">
            <Menu>
            <ext:Menu>
            <Items>
            <ext:MenuItem ID="MenuItem1" runat="server" Text="Save As"></ext:MenuItem>
            <ext:MenuItem ID="Menuitem2" runat="server" Text="Open"></ext:MenuItem>
            </Items>
            </ext:Menu>
            </Menu>
            </ext:ToolbarButton>
            </Items>
            </ext:Toolbar>
        
    
        </form>
    </body>
    </html>

    default.aspx.cs source code

    
    using System;
    using System.Configuration;
    using System.Data;
    using System.Linq;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Xml.Linq;
    
    public partial class _Default : System.Web.UI.Page 
    {
        protected void Page_Load(object sender, EventArgs e)
        {
    
        }
        public override Control FindControl(string id)
        {
            return base.FindControl(id);
        }
    }

    now try to insert a break point in the beginning of the find control method .

    try clicking any menu item in the internet explorer

    now hover over the id parameter , you will find that its value is "submitAjaxEventConfig" value

    whereas in normal scenario , it must bear the string value of the current clicked control's id


    my question is , i need to get the value of menu item's id that was pressed .

    if you attached an ajax method to the current items that are added to the current page , it will work just find
    but what for the menu items that were loaded or created in memory from a data base and doesn't exist at all in the source code of the page but are fetched from the data base using recursion .
    when you try to attach an ajax event for all the items , it calls findcontrol method first but it doesn't find the control it needs because the menus are created on the fly


  4. #4

    RE: hard problem

    i had posted all the code required here , is that what you needed my friend ?
  5. #5

    RE: hard problem

    Hi snoutoz,

    I ran your code sample in debug mode, but the base.FindControl() is never hit. Here's what I was testing.

    Example

    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Coolite.Ext.Web" Namespace="Coolite.Ext.Web" TagPrefix="ext" %>
    
    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
    
        }
        
        public override Control FindControl(string id)
        {
    [BREAKPOINT HERE]        return base.FindControl(id);
        }
    </script>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
        <title>Untitled Page</title>
    </head>
    <body>
        <form id="form1" runat="server">
            <ext:ScriptManager ID="ScriptManager1" runat="server" />
            
            <ext:Toolbar ID="MainToolBar" runat="server">
                <Items>
                    <ext:ToolbarButton ID="Button1" runat="server" Text="File">
                        <Menu>
                            <ext:Menu>
                                <Items>
                                    <ext:MenuItem ID="MenuItem1" runat="server" Text="Save As" />
                                    <ext:MenuItem ID="Menuitem2" runat="server" Text="Open" />
                                </Items>
                            </ext:Menu>
                        </Menu>
                    </ext:ToolbarButton>
                </Items>
            </ext:Toolbar>
        </form>
    </body>
    </html>
    Geoffrey McGill
    Founder
  6. #6

    RE: hard problem

    i am sorry , i had forgotten the ajax method
    just try to add ajaxevents to the menu items

    iam too sorry , as you know i am in the company and so stressed

    
    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Coolite.Ext.Web" Namespace="Coolite.Ext.Web" TagPrefix="ext" %>
    
    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
    
        }
    protected void mymethod(object sender , ajaxEventArgs e)
    {
         // here is the ajax method's body
    }
        
        public override Control FindControl(string id)
        {
    [BREAKPOINT HERE]        return base.FindControl(id);
        }
    </script>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
        <title>Untitled Page</title>
    </head>
    <body>
        <form id="form1" runat="server">
            <ext:ScriptManager ID="ScriptManager1" runat="server" />
            
            <ext:Toolbar ID="MainToolBar" runat="server">
                <Items>
                    <ext:ToolbarButton ID="Button1" runat="server" Text="File">
                        <Menu>
                            <ext:Menu>
                                <Items>
                                    <ext:MenuItem ID="MenuItem1" runat="server" Text="Save As">
                                      <ajaxEvents>
                                       <Click onEvent="mymethod"/>
                                       </ajaxEvents>
                                       </ext:MenuItem>
                                    <ext:MenuItem ID="Menuitem2" runat="server" Text="Open">
                                        <ajaxEvents>
                                       <Click onEvent="mymethod"/>
                                       </ajaxEvents>                                    </ext:MenuItem>
                                </Items>
                            </ext:Menu>
                        </Menu>
                    </ext:ToolbarButton>
                </Items>
            </ext:Toolbar>
        </form>
    </body>
    </html>




    Thanks
  7. #7

    RE: hard problem

    please geo , help me !!
  8. #8

    RE: hard problem

    Hi snoutoz,

    I modified your sample to demonstrate a two different ways to get the ID of the MenuItem that was Clicked. Depending on your scenario will determine which technique you should use.

    I'm still not 100% certain why you are overridding the Page.FindControl Method, but everything appears to work as expected with the sample below.

    Example

    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Coolite.Ext.Web" Namespace="Coolite.Ext.Web" TagPrefix="ext" %>
    
    <script runat="server">
        protected void Menu1_Click(object sender, AjaxEventArgs e)
        {
            this.Label1.Text = string.Format("MenuItemID: {0}", e.ExtraParams["MenuItemID"].ToString());
        }
    
        protected void MenuItem_Click(object sender, AjaxEventArgs e)
        {
            Coolite.Ext.Web.MenuItem item = sender as Coolite.Ext.Web.MenuItem;
            
            if (item != null)
            {
                this.Label1.Text = string.Format("MenuItemID: {0}", item.ID);
            }
        }
        
        public override Control FindControl(string id)
        {
            return base.FindControl(id);
        }
    </script>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
        <title>Untitled Page</title>
    </head>
    <body>
        <form id="form1" runat="server">
            <ext:ScriptManager ID="ScriptManager1" runat="server" />
            
            <h2>Option #1</h2>
            
            <ext:Toolbar ID="Toolbar1" runat="server">
                <Items>
                    <ext:ToolbarButton ID="Button1" runat="server" Text="File">
                        <Menu>
                            <ext:Menu ID="Menu1" runat="server">
                                <Items>
                                    <ext:MenuItem ID="MenuItem1" runat="server" Text="Save As" />
                                    <ext:MenuItem ID="MenuItem2" runat="server" Text="Open" />
                                </Items>
                                <AjaxEvents>
                                    <ItemClick OnEvent="Menu1_Click">
                                        <ExtraParams>
                                            <ext:Parameter Name="MenuItemID" Value="menuItem.id" Mode="Raw" />
                                        </ExtraParams>
                                    </ItemClick>
                                </AjaxEvents>
                            </ext:Menu>
                        </Menu>
                    </ext:ToolbarButton>
                </Items>
            </ext:Toolbar>
            
            <h2>Option #2</h2>
            
            <ext:Toolbar ID="Toolbar2" runat="server">
                <Items>
                    <ext:ToolbarButton ID="ToolbarButton1" runat="server" Text="File">
                        <Menu>
                            <ext:Menu ID="Menu2" runat="server">
                                <Items>
                                    <ext:MenuItem ID="MenuItem3" runat="server" Text="Save As">
                                        <AjaxEvents>
                                            <Click OnEvent="MenuItem_Click"/>
                                        </AjaxEvents>
                                    </ext:MenuItem>
                                    <ext:MenuItem ID="MenuItem4" runat="server" Text="Open">
                                        <AjaxEvents>
                                            <Click OnEvent="MenuItem_Click"/>
                                        </AjaxEvents>
                                    </ext:MenuItem>
                                </Items>
                            </ext:Menu>
                        </Menu>
                    </ext:ToolbarButton>
                </Items>
            </ext:Toolbar>
            
            <ext:Label ID="Label1" runat="server" />
        </form>
    </body>
    </html>
    Hope this helps.


    Geoffrey McGill
    Founder
  9. #9

    RE: hard problem

    hello my friend , first of all thanks very much geo for your interest in helping me , really that a good feeling from you geo.

    thanks again for your consideration . but the problem my friend

    i know that the above samples you provided will work 100% effectively because the menu items are added during the design time , but in my scenario the menu items are created on the fly , polled down from the database using recursion , in other words i build up the menu items totally during runtime reading it from the data source using ado.net

    so when you try to attach the ajax click event for each created menu item during runtime , it works well , but when you try to click the menu item , the click event fires well , but before calling the ajax method of the ajax event handler , it calls findcontrol method to get the menu item control that was clicked , then this pass as an object to the ajax method "sender" parameter .

    so what is the solution to get the created menu items which was clicked ???? by overriding the find control method , then taking the id parameter , searching in your LIST<CustomMenuITEM> collection then returning that menu item that matched the id which will pass as an object to the ajax method sender object parameter

    did you get what i mean now ?

    whatever the menu item that was clicked it returns "submitAjaxEventConfig" string value if you put a break point at the find control method .

    so how can i get the menu item that was clicked which i created during run time?


    Thanks in advance geo .


    Thanks all.
  10. #10

    RE: hard problem

    Nothing changes if you build the controls in code-behind.

    The only golden rule you have to remember for dynamically added asp.net webcontrols is "build early and build often". Meaning, you must add the controls early in the Page lifecycle and you must add the controls on each request.

    If the controls are not added on each request, then the control will not be available on the next request.


    Hope this helps.
    Last edited by geoffrey.mcgill; Feb 20, 2015 at 2:52 PM.
    Geoffrey McGill
    Founder

Similar Threads

  1. Replies: 2
    Last Post: Jul 11, 2012, 5:18 PM
  2. Replies: 0
    Last Post: Jun 06, 2012, 1:37 PM
  3. Replies: 7
    Last Post: Oct 28, 2011, 4:25 PM
  4. Replies: 5
    Last Post: Jun 10, 2009, 5:13 AM

Posting Permissions