Foros del Web » Programación para mayores de 30 ;) » .NET »

No recibo variables desde el onClick

Estas en el tema de No recibo variables desde el onClick en el foro de .NET en Foros del Web. bueno sr... como dice el titulo nopuedo recibir el valor de las variables que trato de enviar a la funcion onClick coloco el codigo...esperoq ueme ...
  #1 (permalink)  
Antiguo 03/11/2009, 07:46
Avatar de jahman  
Fecha de Ingreso: noviembre-2003
Ubicación: Oslo
Mensajes: 230
Antigüedad: 20 años, 5 meses
Puntos: 0
Exclamación No recibo variables desde el onClick

bueno sr...
como dice el titulo nopuedo recibir el valor de las variables que trato de enviar a la funcion onClick coloco el codigo...esperoq ueme puedan ayudar. Saludos .

Código:
//declaro variables globales
    private TextBox textBoxPrisFra;// = new TextBox();
    private TextBox textBoxPrisTil;// = new TextBox();
    private Button searchPris;// = new Button();*/
    private Label IdCat = new Label();

private void BuildFilterControls(){
// muestro textbox dependiendo de la lista
        string[] ExcluList = { "Prisantydning" , "Årsmodell"};/
             for (int er = 0; er < ExcluList.Length; er++)
             {
                this.textBoxPrisFra = new TextBox();
                this.textBoxPrisTil = new TextBox();
                this.searchPris = new Button();
//genero los controles con distintos nombre
                this.textBoxPrisFra.ID = "textBoxPrisFra_"+er;
                this.textBoxPrisFra.Attributes.Add("runat", "server");
                this.textBoxPrisFra.Width = 50;
                this.textBoxPrisFra.CssClass = "font4 colord";
                this.textBoxPrisTil.ID = "textBoxPrisTil_" + er;
                this.textBoxPrisTil.Attributes.Add("runat", "server");
                this.textBoxPrisTil.Width = 50;
                this.textBoxPrisTil.CssClass = "font4 colord";
                this.searchPris.ID = "searchPris_" + er;
                this.searchPris.Text = "Søk";
                this.searchPris.Click += new System.EventHandler(this.searchPris_Click);
                            if (filterCategory.Text == ExcluList[er])//== "Prisantydning")
                            {
                                IdCat.Text = filterCategory.Id.ToString();
                                //tc.Controls.Add(IdCat);
                                tc.Controls.Add(this.textBoxPrisFra);
                                tc.Controls.Add(labelI);
                                tc.Controls.Add(this.textBoxPrisTil);
                                tc.Controls.Add(this.searchPris);
                            }
                        }
}

protected void searchPris_Click(object sender, EventArgs e)
    {
        //aca deberia recibir los valores dependiendo de cual es el q se envio
        //pero no recibo nada.
       string PrisFra = textBoxPrisFra.Text;
        string PrisTil = textBoxPrisTil.Text;

}
  #2 (permalink)  
Antiguo 03/11/2009, 09:47
Avatar de jahman  
Fecha de Ingreso: noviembre-2003
Ubicación: Oslo
Mensajes: 230
Antigüedad: 20 años, 5 meses
Puntos: 0
Respuesta: No recibo variables desde el onClick

agregando

labelI.Text += textBoxPrisFra.ID.ToString()+"<br />";

obtengo los nombre de los textbox los cual seria textBoxPrisFra_0 - textBoxPrisFra_1

ahora no se como puedo rescatar el valor del que haya seleccionado...alguna idea o orientacion
  #3 (permalink)  
Antiguo 04/11/2009, 16:12
Avatar de eperedo  
Fecha de Ingreso: septiembre-2009
Ubicación: Perú
Mensajes: 654
Antigüedad: 14 años, 7 meses
Puntos: 16
Respuesta: No recibo variables desde el onClick

La verdad no podría explicarte el "por qué", mi solución que hasta ahora no me causado problemas felizmente es usar HiddenField.

Espero te sirva

PD: Si alguien te explica el "por qué" de las variables te agradecería que lo compartas.
__________________
Eduardo Peredo
Wigoin
  #4 (permalink)  
Antiguo 05/11/2009, 06:46
Avatar de jahman  
Fecha de Ingreso: noviembre-2003
Ubicación: Oslo
Mensajes: 230
Antigüedad: 20 años, 5 meses
Puntos: 0
Respuesta: No recibo variables desde el onClick

bueno despues de estar horas tratando de hacerlo por fin encontre la solucion

primero los defini como un array de textbox de forma global

Código:
    public Label[] IdCat = new Label [7];// = new Label();
    public TextBox[] textBoxFra = new TextBox[7];
    public TextBox[] textBoxTil = new TextBox[7];
luego desde un array tengo el listado donde deberian mostrarse los textbox
este servira para hacer un filtro de busqueda tipo desde-hasta por lo tanto deberia obtener el "id de categoria" - "int desde" - "int hasta", genero un for y los voy guardando

Código:
string[] ExcluList = { "Prisantydning", "Soverom", "Boareal (kvm)", "Husleie", "Km stand", "Lengde (fot)", "Årsmodell" };//, "Båttype", "Eieform", "Ferietype", "Hovedkategori", "Jobbkategori", "Kategori", "Kommune", "Land", "MC Type", "Modell", "Scooter/Moped", "Sted", "Stillingsnivå", "Type lokaler", "Underkategori" };
             
                        for (int er = 0; er < ExcluList.Length; er++)
                        {
                            if (filterCategory.Text == ExcluList[er])
                            {
                                Button searchPris = new Button();
                                searchPris.ID = "searchPris_"+er;
                                searchPris.Text = "Søk";
                                searchPris.Click += new System.EventHandler(searchPris_Click);

                                IdCat[er] = new Label();
                                IdCat[er].ID = "IdCat_" + er;
                                IdCat[er].Text = filterCategory.Id.ToString();

                                textBoxFra[er] = new TextBox();
                                textBoxFra[er].Width = 50;
                                textBoxFra[er].ID = filterCategory.Text;
                                //textBoxFra[er].TextChanged += new EventHandler(searchPris_Click);

                                textBoxTil[er] = new TextBox();
                                textBoxTil[er].Width = 50;
                                textBoxTil[er].ID = "textBoxTil_" + er;
                                //textBoxTil[er].TextChanged += new EventHandler(searchPris_Click);

                                tc.Controls.Add(textBoxFra[er]);
                                tc.Controls.Add(labelI);
                                tc.Controls.Add(textBoxTil[er]);
                                tc.Controls.Add(searchPris);
                                

                                //labelI.Text += filterCategory.Id.ToString() + "-"+textBoxFra[er].ID.ToString() + "-" + textBoxTil[er].ID.ToString();
                            }
                        }
y al finalizar en el evento onClick los recibo

Código:
for (int er = 0; er < textBoxFra.Length; er++ )
        {
            if (textBoxFra[er] != null)
                if (textBoxFra[er].Text != "")
                {
                    PrisFra += textBoxFra[er].Text;
                    wil += er;
                    ExcluMe = textBoxFra[er].ID.ToString();
                }
                
        }
        for (int er = 0; er < textBoxTil.Length; er++)
        {
            if (textBoxFra[er] != null)
                if (textBoxTil[er].Text != "")
                {
                    PrisTil += textBoxTil[er].Text;
                    //wil = er;
                }
        }
        for (int er = 0; er < IdCat.Length; er++)
        {
            if (er == wil)
            {
                IdCata = IdCat[er].Text;
            }
        }
en unas semanas podras ver el resultado en www.rubrikk.no.
saludos. Gracias por tu respuesta.
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 12:18.