locked
Problem Rendering controls RRS feed

  • Question

  • User939516264 posted

    I am using the following code for Rendering a control 

    protected
    override void Render(HtmlTextWriter writer)

    {

          base.Render(writer);

          writer.AddStyleAttribute(HtmlTextWriterStyle.BorderWidth, "3");

          writer.AddStyleAttribute(HtmlTextWriterStyle.BorderStyle, BorderStyle.Inset.ToString());

          writer.AddStyleAttribute(HtmlTextWriterStyle.BorderColor, "Blue");

          writer.AddStyleAttribute(HtmlTextWriterStyle.BackgroundColor, Color.Aqua.ToString());

          writer.RenderBeginTag(HtmlTextWriterTag.Table); //<Table>

          {

                writer.RenderBeginTag(HtmlTextWriterTag.Tr); //<Tr>

                {

                      for (int i = 0; i < NumberOfBars; i++)

                      {

                            writer.RenderBeginTag(HtmlTextWriterTag.Td); //<Td>

                            {

                                  writer.AddStyleAttribute(
    HtmlTextWriterStyle.Height, Heights[i]);            //*************PROBLEM HERE

                                  writer.AddStyleAttribute(HtmlTextWriterStyle.Width, "40");                  //*******PROBLEM HERE

                                  writer.AddStyleAttribute(HtmlTextWriterStyle.BackgroundColor, "Yellow");

                                  writer.AddStyleAttribute(HtmlTextWriterStyle.Color, "Black");

                                  writer.RenderBeginTag(HtmlTextWriterTag.Hr); //<Hr>

                                  writer.RenderEndTag();

                            }

                            writer.RenderEndTag(); //</Td>

                      }

                  }

                  writer.RenderEndTag(); //</Tr>

                }

                writer.RenderEndTag(); //</Table>

          }

     

    The control is being displayed, but the bars (HR's) are not displaying. They is not recieveing Width and Height, where as I am assigning them as string.

    Thursday, April 3, 2008 7:09 AM

Answers

  • User-16411453 posted

    There's no object to apply the style to, but if there was, it would be the following

    writer.AddStyleAttribute(HtmlTextWriterStyle.Height, Heights[i].ToString & "px");            //*************PROBLEM HERE

                                  writer.AddStyleAttribute(HtmlTextWriterStyle.Width, "40px");                  //*******PROBLEM HERE

     

     But your way off track on this, I recommend the following
     

    Dim table As Table
    table = New Table
    table.Style.Add(HtmlTextWriterStyle.Height, Heights(i).ToString & "px") - Not sure about your square brackets [i]
    table.Style.Add(HtmlTextWriterStyle.Height, "40px")
    
    Controls.Add(table)
    
    Dim tr As TableRow
    tr = New TableRow
    table.Controls.Add(table)
    
    writer.Render(table)
      
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, April 4, 2008 6:03 PM