Dynamically added button's direct event does not work

  1. #1

    Dynamically added button's direct event does not work

    Please take a look at this:

    protected void Page_Load(object sender, EventArgs e)
    {
        Ext.Net.Button b1 = new Ext.Net.Button(); 
        b1.Text = "test button";
    
        b1.DirectEvents.Click.Event += new ComponentDirectEvent.DirectEventHandler(Click_Event);
        b1.AddTo(pnlCenter);
    }
    
    void Click_Event(object sender, DirectEventArgs e)
    {
        X.Msg.Alert("test message", "test");
    }
    The button is dynamically added to the pnlCenter which is on the aspx page.

    This produces the following error:

    The control with ID 'id1a62f466f3ff47c985aad859f77faac0' not found
    Description: An unhandled exception occurred during the execution of
    the current web request. Please review the stack trace for more
    information about the error and where it originated in the code.
    
    Exception Details: System.Web.HttpException: The control with ID
    'id1a62f466f3ff47c985aad859f77faac0' not found
    
    Source Error:
    
    An unhandled exception was generated during the execution of the
    current web request. Information regarding the origin and location of
    the exception can be identified using the exception stack trace below.
    
    Stack Trace:
    
    [HttpException (0x80004005): The control with ID
    'id1a62f466f3ff47c985aad859f77faac0' not found]
      Ext.Net.ResourceManager.RaisePostBackEvent(String eventArgument) +1109
      System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
    sourceControl, String eventArgument) +13
      System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +176
      System.Web.UI.Page.ProcessRequestMain(Boolean
    includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
    +5563
    How to dynamically add a control to the page and use its direct event handler?

    Regards,
    Darko

    EDIT: The code actually works when the button is outside of the panel (directly on the aspx form).
    But when the button is put inside the panel the error message appears.
    Any ideas how to resolve this?
    Last edited by geoffrey.mcgill; Feb 08, 2011 at 5:53 PM. Reason: please use [CODE] tags
  2. #2
    Hi,

    Please replace
    b1.AddTo(pnlCenter);
    by

    pnlCenter.Items.Add(b1);
  3. #3
    Quote Originally Posted by Vladimir View Post
    Hi,

    Please replace
    b1.AddTo(pnlCenter);
    by

    pnlCenter.Items.Add(b1);
    Thanks for the quick reply.

    The Click_Event now fires but the alert is not displayed!?
  4. #4
    Hi,

    Need to call 'Show' method
    X.Msg.Alert("test message", "test").Show();
  5. #5
    Thanks again.

    I'm a beginner in Ext.Net so please don't mind the 'stupid' questions. :D:
  6. #6

    i encounter same problem and fix proposed here didnt work

    [HttpException (0x80004005): The control with ID 'button-1096' not found]
    Ext.Net.ResourceManager.RaisePostBackEvent(String eventArgument) +1079
    System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler sourceControl, String eventArgument) +13
    System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData) +9665314
    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1724

    while (x>10){
    while(10<k){
                            Ext.Net.Button but = new Ext.Net.Button();
                            but.ID = events_on_map[x].getfvalues() + "but_" + events_on_map[x].getevid();
                            but.Text = "" + events_on_map[x].getevid();
                            but.Height = 15;
                            //but.On("click", new JFunction("alert('The button is clicked');", "button", "e"));
                            but.DirectEvents.Click.Event += new ComponentDirectEvent.DirectEventHandler(Click_Event);
                            days[k].Items.Add(but);
    
                            //but.DirectClick += bt;
                            //inserrt here the button which will open the window of event
                            //days[k].Title = events_on_map[x].getstats() +"-"+  events_on_map[x].getevid() + "; ";
    }}
            thisroom.Items.Add(days);
    
    ///////////////////
      private void bt(object sender, DirectEventArgs e)
        {
            X.Msg.Alert("Server", e).Show();
            //X.Msg.Notify("Server Time", DateTime.Now.ToLongTimeString()).Show();
            //    X.Msg.Alert("Status", "." + sender+e).Show();
        }
    //nothing works
    Last edited by dim4ik2008; Jan 15, 2016 at 12:26 PM. Reason: new info

Similar Threads

  1. Replies: 2
    Last Post: May 21, 2012, 9:25 AM
  2. Replies: 13
    Last Post: Jul 29, 2011, 4:24 AM
  3. Replies: 1
    Last Post: Jun 07, 2011, 9:09 PM
  4. Dynamically Added Button Direct Event Does Not Work
    By rosencrantz in forum 1.x Help
    Replies: 1
    Last Post: Apr 19, 2011, 9:41 AM
  5. Replies: 12
    Last Post: Jan 01, 2011, 1:36 AM

Posting Permissions