locked
My Server Control is multiplied At the time that change you properties RRS feed

  • Question

  • User-1079078450 posted

    My Server Control is multiplied At the time that change you  properties, por example,  at change the width (design time), the Server control is multiplied increasingly.  In runtime, the control have a function normal, but in the design, your behavior is anormal. I have a HTML Table, inside of this Table, add controls (1 label, 1image and 1 htmllink for cell), at final,  my table contain a set of cells with yout controls, in the metod Render, execute the next line:

    Table.RenderControl(writer);

    When add this server control in a page .aspx, the control appears normal, but when change the width, the cells and your content are multiplied. Thanks for yor help.

    Sunday, September 25, 2011 4:35 PM

Answers

  • User-1079078450 posted

    I has resolved the problem.    The solution is create arrays of controls for the label, image and  hyperlink, con this action  the multiplied of controls not succed.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, September 27, 2011 5:57 PM

All replies

  • User3866881 posted

    When add this server control in a page .aspx, the control appears normal, but when change the width, the cells and your content are multiplied.

    Please point it out by showing us your screenshots to compare with each other.

    If possible, show us your codes, please.

    Thx again

    Monday, September 26, 2011 9:50 PM
  • User-1079078450 posted

    Here I  show my code:

     protected override void Render(HtmlTextWriter writer)
            {

                if (CadenaConexion != null)
                {
                    Datos datoss = new Datos();
                  
                    if (Consulta != null)
                    {

                        DataTable dtDatos = datoss.consultaGeneral(cadenaConexion, consulta);

                        configuracion = new Configuracion();
                        int i = -1;
                        int j = 0;
                        int nivel = 1;
                        int max = 0;
                        int inicio = 0;
                        int fila, columna;

                        //Obtiene el nivel maximo y el numero de renglones
                        int nivelMaximo = configuracion.obtieneNivelMaximo(dtDatos);
                        int renglones = configuracion.obtieneNumeroRenglones(dtDatos);
                        int[] inicios = new int[nivelMaximo];

                        //Calcula el numero de subniveles para cada nivel
                        inicios = configuracion.obtieneInicios(dtDatos, nivelMaximo);

                        //Calcula el numero de subniveles maximo
                        max = configuracion.obtieneNivelMaximo2(dtDatos);

                        //Calcula la media para representar  los  subniveles
                        inicio = configuracion.obtieneMedia(max);
                        i = inicio;

     

                        //Calcula donde iniciara el mostrado de imagenes
                        foreach (DataRow dr in dtDatos.Rows)
                        {
                            if (nivel != int.Parse(dr.ItemArray[2].ToString()))
                            {
                                j = (nivel * 2);
                                nivel = int.Parse(dr.ItemArray[2].ToString());

                                if (inicios[nivel - 1] == 1)
                                    i = inicio;
                                else if (inicios[nivel - 1] == max) i = 0;
                                else i = (max - 1) - inicios[nivel - 1];
                            }

                          
                            tblControl = configuracion.inicializacionTabla(tblControl, Horientacion, max, nivelMaximo, i, j);

                            fila = configuracion.fila;
                            columna = configuracion.columna;
                            // configuracion.configuraEtiqueta(dr.ItemArray[1].ToString()).RenderControl(writer);
                            tblControl.Rows[fila].Cells[columna].Controls.Add(configuracion.configuraEtiqueta(dr.ItemArray[1].ToString()));

                            //Configuracion de la imagen
                            string url = "~/img/" + dr.ItemArray[4].ToString().Trim() + dr.ItemArray[0].ToString().Trim() + ".jpg";
                            tblControl.Rows[fila].Cells[columna].Controls.Add(configuracion.configuraImagen(url));

                            //Configuracion del boton
                            HyperLink btnDeta = configuracion.configuracionBoton(dr.ItemArray[5].ToString().Trim());
                            tblControl.Rows[fila].Cells[columna].Controls.Add(btnDeta);
                            int factor = ((int.Parse(dr.ItemArray[0].ToString())) - 1) % 10;
                            int precedente = int.Parse(dr.ItemArray[3].ToString());

                            //insercion de flechas
                            tblControl = configuracion.insertaImagenFlecha(tblControl, Horientacion, precedente, inicio, i, j);
                            i++;
                        }
                      
                        Panel pnlControl = new Panel();
                        pnlControl.Width = 50;
                      
                        pnlControl.Controls.Add(tblControl);
                        pnlControl.RenderControl(writer);
                    }//fin if consulta
                }//fin del if conexion
            }//fin del metodo render

      

    This is the metod Render of my Server Control.  Any observation, is welcome.

    Monday, September 26, 2011 11:26 PM
  • User3866881 posted

    Hello again,

    Very sorry but your codes aren't complete....

    What's defination of Datos?

    What's consultaGeneral???

    ………………

    I've sent you a private message, please see "Inbox" when you log in.

    Thx again

    Tuesday, September 27, 2011 1:05 AM
  • User-1079078450 posted

    Ok, now show my classes:

    Datos.cs:

    public class Datos
    {
     public Datos()
     {
     
     }
        public DataTable consultaGeneral(string conexion, string Consulta)
        {
            SqlConnection cn = new SqlConnection(conexion);
            String consulta = Consulta;

            SqlDataAdapter da = new SqlDataAdapter(consulta, cn);
            DataTable dtTotal = new DataTable();
            da.Fill(dtTotal);
            return dtTotal;
        }
    }

    Configuracion.cs:

    public class Configuracion
    {
        public int fila, columna;

        public HtmlTable inicializacionTabla(HtmlTable tabla, String horientacion, int max, int nivelMaximo, int i, int j)
        {
            if (horientacion=="horizontal")
            {
                tabla = inicializaTabla(tabla, max, (nivelMaximo * 2) - 1);
                fila = i;
                columna = j;
            }
            else
            {
                tabla = inicializaTabla(tabla, (nivelMaximo * 2) - 1, max);
                fila = j;
                columna = i;
            }
            return tabla;
        }

        private HtmlTable inicializaTabla(HtmlTable tabla, int nRen, int nCol)
        {
            //if (tabla.Rows.Count < 1)
            //{
                for (int i = 0; i < nRen; i++)
                {
                    HtmlTableRow tRow = new HtmlTableRow();


                    tabla.Rows.Add(tRow);
                    for (int j = 0; j < nCol; j++)
                    {
                        HtmlTableCell tCell = new HtmlTableCell();
                        tCell.Align = "Center";
                        tCell.VAlign = "Bottom";
                        tCell.Width = "30";
                        tCell.Height = "30";                  
                      //  tCell.Style.Value = "background-color: #00FF00";
                        tRow.Cells.Add(tCell);                
                    }
                }
            //}
            return tabla;
        }

        public int obtieneNivelMaximo(DataTable dt)
        {
            return (int)dt.Compute("Max(Nivel)", "");
        }

        public int obtieneNumeroRenglones(DataTable dt)
        {
            return dt.Rows.Count;
        }

        public int[] obtieneInicios(DataTable dt, int tamano)
        {
            int[] inicios = new int[tamano];
            foreach (DataRow dr in dt.Rows)
            {

                int valor = int.Parse(dr.ItemArray[0].ToString()) % 10;
                if (valor > inicios[int.Parse(dr.ItemArray[2].ToString()) - 1])
                    inicios[int.Parse(dr.ItemArray[2].ToString()) - 1] = valor;
            }
            return inicios;
        }

        public int obtieneNivelMaximo2(DataTable dt)
        {
            int max = 0;
            foreach (DataRow dr in dt.Rows)
            {
                int valor = int.Parse(dr.ItemArray[0].ToString()) % 10;
                if (valor > max)
                    max = valor;
            }
            return max;
        }

        public int obtieneMedia(int max)
        {
            int inicio = 0;
            decimal division = max / 2;
            if (max > 2)
            {
                inicio = int.Parse(Math.Truncate(division).ToString());
            }
            int i = inicio;
            return inicio;
        }

        public Label configuraEtiqueta(String contenido)
        {
            Label lblEtiqueta = new Label();

            lblEtiqueta.ControlStyle.Width = 50;
            ////    lblEtiqueta.Style.Value = "font-family: Arial; font-size: xx-small;color: #000000";
            lblEtiqueta.Text = contenido;
            lblEtiqueta.Font.Size = FontUnit.XLarge;
            lblEtiqueta.ForeColor = System.Drawing.Color.Black;
            lblEtiqueta.Font.Bold = true;
            lblEtiqueta.Font.Name = "Arial";
            lblEtiqueta.Font.Size = 7;

            //FontInfo = new System.Drawing.Font("Arial", 12, System.Drawing.FontStyle.Bold);

            //lblEtiqueta.Font = "";   
            // string r=   new System.Drawing.Font("Arial", 12, System.Drawing.FontStyle.Bold);


            return lblEtiqueta;
        }

        public Image configuraImagen(string ruta)
        {
            Image imgsubProceso = new Image();
            string url = ruta;
            imgsubProceso.ImageUrl = url;
            imgsubProceso.ImageAlign = ImageAlign.Middle;
            imgsubProceso.Width = 50;
            imgsubProceso.Height = 50;
            imgsubProceso.AlternateText = "Subproceso";
            return imgsubProceso;
        }

        public HtmlTable insertaImagenFlecha(HtmlTable tblControl, String horientacion, int precedente, int inicio, int i, int j)
        {
            if (precedente != 0)
            {
                Image imgFlecha = new Image();
                imgFlecha.Width = 30;
                imgFlecha.Height = 30;

                if (horientacion=="horizontal")
                {
                    if (i < inicio) imgFlecha.ImageUrl = "~/img/flechaDerecha-45.png";
                    else if (i == inicio) imgFlecha.ImageUrl = "~/img/flechaDerecha.png";
                    else imgFlecha.ImageUrl = "~/img/flechaDerecha45.png";
                    tblControl.Rows[i].Cells[j + 1].Controls.Add(imgFlecha);
                    tblControl.Rows[i].Cells[j + 1].Width = "30";
                    tblControl.Rows[i].Cells[j + 1].Height = "30";
                    tblControl.Rows[i].Cells[j + 1].VAlign = "Center";
                }
                else
                {
                    if (i < inicio) imgFlecha.ImageUrl = "~/img/flechaAbajo-45.png";
                    else if (i == inicio) imgFlecha.ImageUrl = "~/img/flechaAbajo.png";
                    else imgFlecha.ImageUrl = "~/img/flechaAbajo45.png";
                    tblControl.Rows[j + 1].Cells[i].Controls.Add(imgFlecha);
                    tblControl.Rows[j + 1].Cells[i].Width = "30";
                    tblControl.Rows[j + 1].Cells[i].Height = "30";
                    tblControl.Rows[j + 1].Cells[i].VAlign = "Center";
                }
            }
            return tblControl;
        }

        public HyperLink configuracionBoton(String url)
        {
            HyperLink lnkDetalles = new HyperLink();
            lnkDetalles.Text = "Detalles";
           // lnkDetalles.Style.Value = "font-family: Arial; font-size: xx-small;width: 55px; height: 10px;text-decoration: underline;color: #000002";
          //  lnkDetalles.BackColor = System.Drawing.Color.Bisque;

            lnkDetalles.Font.Size = FontUnit.XLarge;
            lnkDetalles.ForeColor = System.Drawing.Color.Black;
            lnkDetalles.Font.Name = "Arial";
            lnkDetalles.Font.Size = 6;


            lnkDetalles.Attributes.Add("OnClick", "prueba('" + url + "');");
            return lnkDetalles;
        }
    }

     

     

    Tuesday, September 27, 2011 2:41 PM
  • User-1079078450 posted

    I has resolved the problem.    The solution is create arrays of controls for the label, image and  hyperlink, con this action  the multiplied of controls not succed.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, September 27, 2011 5:57 PM