[CLOSED] Create a dynamic event for dynamic components.

Page 1 of 2 12 LastLast
  1. #1

    [CLOSED] Create a dynamic event for dynamic components.

    Hi,
    I have a problem to create dynamic event to my buttons.

     protected void CriarTextBoxIndices(object sender, DirectEventArgs e)
            {
                ECMContext ECMContextBll = new Stoque.ECM.BLL.ECMContext();      
                var indexTP = int.Parse(this.MultiSelectTipoDocumentoID.SelectedItems[0].Value);
                var tipoDocumentoIndices = ECMContextBll.ObterTipoDocumentoId(indexTP, Expandir.TipodocumentoIndices);
    
                if (tipoDocumentoIndices != null)
                {
                    int X = 10;
                    int Y = 10;
    
                    IndiceBusca indiceBusca;
    
                    foreach (Tipodocumento_Indice tipoDocumentoIndice in tipoDocumentoIndices.tipodocumento_indices)
                    {
                        //Verifica se o indice pode ser exibido
                        if (!tipoDocumentoIndice.invisivel)
                        {
                            indiceBusca = new IndiceBusca();
                            Ext.Net.CompositeField compositeField = new CompositeField();
                            compositeField.ID = "compositeField" + tipoDocumentoIndice.indice.id.ToString();
                            compositeField.X = X;
                            compositeField.Y = Y;
                            compositeField.FieldLabel = tipoDocumentoIndice.indice.nome;
                            compositeField.LabelAlign = LabelAlign.Top;
    
                            var comboBoxIndice = this.CriarComboBox(tipoDocumentoIndice.indice.id, "cbxOperador");
    
                            indiceBusca.operador = comboBoxIndice.ID;
                            indiceBusca.nome = tipoDocumentoIndice.indice.nome;
    
                            foreach (var item in Operador.MontaOperadores(tipoDocumentoIndice.indice.tipo))
                                comboBoxIndice.Items.Add(item);
    
                            if (tipoDocumentoIndice.indice.tipo == (int)Tipo.Inteiro)
                            {
                                var txtIndice = this.CrirTextFiel(tipoDocumentoIndice.indice.id, "txtIndice", 150);
                                compositeField.Items.Add(txtIndice);
    
                                indiceBusca.valor = txtIndice.ID;
    
                            }
                            else if (tipoDocumentoIndice.indice.tipo == (int)Tipo.Data)
                            {
                                var txtDateFiel = this.CrirDateFiel(tipoDocumentoIndice.indice.id, "dateIndice", 150);
                                compositeField.Items.Add(txtDateFiel);
    
                                indiceBusca.valor = txtDateFiel.ID;
    
                            }
                            else if (tipoDocumentoIndice.indice.tipo == (int)Tipo.ComboBox)
                            {
                                var cbxIndice = this.CriarComboBox(tipoDocumentoIndice.indice.id, "cbxIndice", 150);
                                compositeField.Items.Add(cbxIndice);
    
                                indiceBusca.valor = cbxIndice.ID;
                            }
    
                            var btnCriarIndice = CriarImageButton(tipoDocumentoIndice.indice.id, "imgButton", imagemAdicionar);
                            btnCriarIndice.DirectEvents.Click.Event += btnCriarIndice_Click; 
    
                            compositeField.Items.Add(comboBoxIndice);
                            compositeField.Items.Add(btnCriarIndice);
    
                            this.PanelComponenteDinamico.Add(compositeField);
    
                            Operador.LimpaOperadores();
    
                            this.Controles.Add(indiceBusca);
                            //só para teste
                            this.Session["Operadores"] = Controles;
    
                            Y = Y + 50;
                        }
                    }
                    this.PanelComponenteDinamico.UpdateContent();                              
                }
            }
    My event button click:

      protected void btnCriarIndice_Click(object sender, EventArgs e)
            {
                X.Msg.Alert("value", "Teste").Show();
            }
    Error : The control with ID 'imgButton3934' not found

    I know that the controls were not recorded.

    How do I create these events?

    Best Regards,

    Stoque.
    Last edited by Daniil; May 17, 2011 at 1:58 PM. Reason: [CLOSED]
  2. #2
    Try

    protected void btnCriarIndice_Click(object sender, DirectEventArgs e) (instead of object sender, EventArgs e)



    Martin
  3. #3
    Quote Originally Posted by CarWise View Post
    Try

    protected void btnCriarIndice_Click(object sender, DirectEventArgs e) (instead of object sender, EventArgs e)



    Martin
    Thanks Martin but does not work.
  4. #4
    Hi,

    Possible solutions:

    - recreate dynamic controls for each request in the Page_Init (for example, in the CriarTextBoxIndices place some variable to the session and check that variable in the page init handler, if the variable exists then widgets must be recreated on the server side (without rerendering) )

    - use DirectMethods instead DirectEvents
  5. #5
    Quote Originally Posted by Vladimir View Post
    Hi,

    - use DirectMethods instead DirectEvents
    Hi Vladimir,
    You have an example for the second solution?

    I tried with this code did not work.
    btnCriarIndice.Listeners.Click.Handler += "btnCriarIndice_Click();";

     [DirectMethod]
            protected void btnCriarIndice_Click()
            {
                X.Msg.Alert("value", "Teste").Show();
            }
  6. #6
    Hi,

    Your code appears correct, except .Handler is a property (type of string), not an Event.

    Example

    btnCriarIndice.Listeners.Click.Handler = "btnCriarIndice_Click();";
    Geoffrey McGill
    Founder
  7. #7
    Hi Geoffrey,

    but not work.

    I have to create an event for each button created dynamically.
    At the click of these buttons need to re-create another textbox and another button below.
  8. #8
    Hi,

    1. Please create DirectMethod (it must be public and arguments must be simple)
    https://examples1.ext.net/#/Events/D...hods/Overview/

    2. Use that direct method as in the following code
    btnCriarIndice.Listeners.Click.Handler = "#{DirectMethods}.MyDirectMethod();";
  9. #9
    Thanks a lot Vladimir and Geoffrey ,
    please mark as solved.

    I did so but my method was as protected.
    btnCriarIndice.Listeners.Click.Handler += "Ext.net.DirectMethods.btnCriarIndice_Click();";
  10. #10
    One more question please.
    Extraparameter DirectMethod accept?
    How do I know which button was clicked?
    I wanted to retrieve the ID of the parent (CompositeField) in my method.
Page 1 of 2 12 LastLast

Similar Threads

  1. Dynamic create a TextField and Button
    By cnet2001 in forum 1.x Help
    Replies: 3
    Last Post: Dec 17, 2010, 1:16 AM
  2. Replies: 1
    Last Post: Dec 16, 2010, 12:08 PM
  3. problem with create control dynamic
    By jhenriquecosta in forum 1.x Help
    Replies: 0
    Last Post: Jun 02, 2010, 3:34 AM
  4. [CLOSED] Create dynamic grid from XML
    By Hari_CSC in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: Apr 07, 2010, 1:43 PM
  5. How to dynamic create DesktopWindow?
    By iscript in forum 1.x Help
    Replies: 2
    Last Post: Aug 07, 2009, 2:25 AM

Tags for this Thread

Posting Permissions