ajax event problem

Page 1 of 2 12 LastLast
  1. #1

    ajax event problem

    hello everybody .
    in this example in my work , i load the menu of the web page from a data base , so i have to provide the ajax event for each menu item that is loaded i pass in ajaxEventHandler to each loaded menu item

    but when the menu is rendered completely , i try to click one item , it gives me an error , unhandled exception , because the control ID is not found

    Server Error : 500

    bad response


    The control with id 'ctl234' not found

    unhandled exception found


    follow the stack trace below blah blah blah


    why , and every menu item has a name and id

    i don't name my menu items like that ctl+a number

    why 'ctl234' i don't have that menu item
  2. #2

    RE: ajax event problem

    Hi snoutoz,

    Does the following forum post help solve the problem, see*http://forums.ext.net/showthread.php...-1.aspx#bm2547




    Geoffrey McGill
    Founder
  3. #3

    RE: ajax event problem

    the problem here , my friend , is that when you design the menus by hand , the ajax events work just fine

    but i told you that the menus are created on the fly from runtime , the items of the menu don't exist until the page is fully loaded because the menus come from the data base . so when the ajax event makes its request to the page , it doesn't find the element


    how can i get the menu item , or can you give me any reference paper about ajax events

  4. #4

    RE: ajax event problem

    ...or can you give me any reference paper about ajax events
    Yep, no problem. I'll just need a bit of time to get that together for you.*


    Geoffrey McGill
    Founder
  5. #5

    RE: ajax event problem

    you know , actually there is a difference between the hard coded menu items that are added by hand to the xhtml code

    and the menu items that are added programmatically during run time , because when the event of the menu item click fires it initiates a findControl(string id) method of the web page class to find the current menu item , so in the hard coded menu items that findcontrol returns successfully the completed object but in the in memory representation of the menu item , that doesn't work and you have to override that method .
    but there is another problem , why when i debug that overriden findControl(string id) method , the id always becomes "submitAjaxEventConfig" what is that id ?????????????

    please tell me ??????????????
  6. #6

    RE: ajax event problem

    If you do not explicitly set the .ID property of the control, the .NET will auto-generate an ID for you. This is default functionality of the .NET Framework.

    Posting a simplified .aspx code sample demonstrating how to reproduce a problem would help us better understand exactly what might be going wrong and offer suggestions on how to fix.

    Geoffrey McGill
    Founder
  7. #7

    RE: ajax event problem

    here is the code in the default.aspx xhtml view

    <ext:Toolbar ID="MainToolBar" runat="server" Width="1239" IDMode="Static">
    <Items>

    </Items>
    </ext:Toolbar>




    in the Custom.cs file that loads the items



    
    public class CustomMenuItem : Coolite.Ext.Web.MenuItem
    {
        #region "private Attributes"
    
        string _name;
        int _MenuPosition;
        int _Pky;
        int Parent_Ky;
        string _Description;
        int _formKy;
        System.Drawing.Image _MenuImage;
        string _Parameters;
        string _options;
        string ajaxMethod;
    
        Coolite.Ext.Web.ComponentAjaxEvent.AjaxEventHandler handler;
        #endregion
    
        #region "Public properties"
    
        public Coolite.Ext.Web.ComponentAjaxEvent.AjaxEventHandler GetHandler
        {
            get { return this.handler; }
            set { this.handler = value; }
        }
        public string AjaxMethod
        {
            get { return this.ajaxMethod; }
            set { this.ajaxMethod = value; }
    
        }
        public System.Drawing.Image MenuImage
        {
            get { return this._MenuImage; }
            set { this._MenuImage = value; }
        }
    
        public string Parameters
        {
            get { return this._Parameters; }
            set { this._Parameters = value; }
        }
        public string Options
        {
            get { return this._options; }
            set { this._options = value; }
        }
    
        public string GetName
        {
            get { return this._name; }
            set
            {
                this._name = value;
                base.Text = value;
                base.ID = "item" + this.Key.ToString();
                //base.ID = (Guid.NewGuid()).ToString();
            }
        }
        public int MenuPosition
        {
            get { return this._MenuPosition; }
            set { this._MenuPosition = value; }
        }
        public int Parent_Key
        {
            get { return this.Parent_Ky; }
            set { this.Parent_Ky = value; }
        }
        public string Description
        {
            get { return this._Description; }
            set { this._Description = value; }
        }
        public int GoToForm
        {
            get { return this._formKy; }
            set { this._formKy = value; }
        }
        public int Key
        {
            get { return this._Pky; }
            set { this._Pky = value; }
        }
    
        #endregion
    
        public void AddChildern(CustomMenuItem currentitem , DataTable dt)
        {
            try
            {
                //this is the base condition 
                if (!HasChildern(currentitem,dt))
                {
                    Coolite.Ext.Web.Parameter param = new Coolite.Ext.Web.Parameter();
                    param.Mode = Coolite.Ext.Web.ParameterMode.Raw;
                    param.Name = "itemid";
                    param.Value = String.Format("{0}.id", this.ID);
                    currentitem.AjaxEvents.Click.Event += handler;
                    currentitem.AjaxEvents.Click.ExtraParams.Add(param);
                    
                    
    
                    return;
                }
                else
                {
                    Coolite.Ext.Web.Menu menu = new Coolite.Ext.Web.Menu();
    
                    //get all the childern of the current item
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        CustomMenuItem item = new CustomMenuItem();
    
                        int parent_key = int.Parse(dt.Rows[i]["parent_ky"].ToString());
                        
                        if (parent_key == currentitem.Key)
                        {
                            //add the current item to the menu of these items
                            item.Key = int.Parse(dt.Rows[i]["pky"].ToString());
                            item.GetName = dt.Rows[i]["name"].ToString();
                            string position = dt.Rows[i]["men_pos"].ToString();
                            if (position != string.Empty)
                            {
                                item.MenuPosition = int.Parse(position);
                            }
                            else
                            {
                                item.MenuPosition = 0;
                            }
                            item.Parent_Key = parent_key;
                            //add the event handler
                            
                            //item.Listeners.Click.EventArgument = ajaxMethod + "(" + this.ID + ")";
                            //Get the childern of the current menu item
                            item.AddChildern(item, dt);
                            //add the current menu to the menu collection
                            menu.Items.Add(item);
                        }
                    }
                    //add the current menu to the current menu item
                    currentitem.Menu.Add(menu);
                }
    
            }
            catch (Exception s)
            {
                return;
            }
        }
    
        bool HasChildern(CustomMenuItem currentitem , DataTable dt)
        {
            try
            {
                bool hasChildern = false;
    
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    int parent_key = int.Parse(dt.Rows[i]["parent_ky"].ToString());
    
                    if (parent_key == currentitem.Key)
                    {
                        hasChildern = true;
                    }
                }
                return hasChildern;
    
            }
            catch (Exception s)
            {
                return false;
            }
        }
    }

    in the menus.cs




    
    public class Menus
    {
        public static List<CustomToolBar> GetButtons(Coolite.Ext.Web.ComponentAjaxEvent.AjaxEventHandler handler)
        {
            try
            {
                //open connection
                SqlConnection connection = Connection.OpenConnection();
                //create sql command
                if (connection != null)
                {
                    //create sql command 
                    SqlCommand command = new SqlCommand();
                    command.Connection = connection;
                    command.CommandText = "GetMenus";
                    command.CommandType = CommandType.StoredProcedure;
                    //execute the sql command
                    SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection);
    
                    //create data table
                    DataTable dt = new DataTable();
                    dt.Load(reader);
    
                    List<CustomToolBar> buttons = new List<CustomToolBar>();
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        CustomToolBar button = new CustomToolBar();
    
                        int ParentKey = int.Parse(dt.Rows[i]["parent_ky"].ToString());
    
                        //that means it is a parent menu
                        if (ParentKey == 0)
                        {
                            button.GetName = dt.Rows[i]["name"].ToString();
                            button.Key = int.Parse(dt.Rows[i]["pky"].ToString());
                            button.IDMode = Coolite.Ext.Web.IDMode.Static;
                            string position = dt.Rows[i]["men_pos"].ToString();
                           
                            if (position != String.Empty)
                            {
                                button.MenuPosition = int.Parse(position);
                            }else
                                button.MenuPosition = 0;
                            button.Parent_Key = ParentKey;
    
                            //add the event handler for the current Tool Bar Button item
                            button.GetHandler = handler;
                            //check to see if it has childern
                            button.AddChildern(button, dt);
    
                            //add the current button to the list of buttons
                            buttons.Add(button);
                        }
                    }
    
                    //return the list of buttons with its subchildern
                    return buttons;
    
                }
                else return null;
            }
            catch (Exception s)
            {
                return null;
            }
        }
    }





    in the page load event

    here is the code that loads the menus


    in default.aspx.cs

    
     buttons = Menus.GetButtons(new Coolite.Ext.Web.ComponentAjaxEvent.AjaxEventHandler(MenuItem_Click));
                      
                    
                    //add the current menu to the application
    
                    Time.GetTime = DateTime.Now;
    
                    DisplayLabel.Text = Time.GetElapsed.ToString();
    
                    //add them one after the other
                    foreach (CustomToolBar button in buttons)
                    {
                        try
                        {
                            //add the current button
                            MainToolBar.Items.Add(button);
                        }
                        catch (Exception s)
                        {
                            Response.Write(s.Message);
                        }
                    }


    any solution my friend
  8. #8

    RE: ajax event problem

    please my friend, can you have a look at my above code , please comment or help me as soon as possible because i am at work and this is a task
  9. #9

    RE: ajax event problem

    Hi,

    Do you recreate all dynamic controls on reach request (even AjaxEvent) ? I think full example which we can test will force help


  10. #10

    RE: ajax event problem

    my question is so simple , just take it easy and you can test it yourself too simply in your house

    just create a toolbar with two tool bar buttons for example each of which has two menu items attached .
    In the code behind view of the default.aspx page try to override the findControl method

    and insert a break point there , then try to debug your solution .

    you will find that the parameter ID of that method always has the value "AjaxsubmitEventConfig" whatever menu item you have clicked

    whereas in normal asp.net controls that id each time carries the id of the control which you have clicked , before executing the ajax method itself


    thank you

    so simple and easy


Page 1 of 2 12 LastLast

Similar Threads

  1. Ajax Event not working
    By vickygajula in forum 1.x Help
    Replies: 3
    Last Post: Dec 09, 2010, 5:19 PM
  2. ajax event confirmation
    By [WP]joju in forum 1.x Help
    Replies: 2
    Last Post: Dec 10, 2009, 6:17 AM
  3. ajax event success
    By [WP]joju in forum 1.x Help
    Replies: 3
    Last Post: Dec 10, 2009, 5:27 AM
  4. [CLOSED] Before event of a ajax event.
    By Riset in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Nov 27, 2009, 12:07 PM
  5. Ajax Event Confirmation Tag
    By akozmic in forum 1.x Help
    Replies: 6
    Last Post: Apr 20, 2009, 7:23 PM

Posting Permissions