Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6553783
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:37:21+00:00 2026-05-25T12:37:21+00:00

I have a solution that works, yet it doesn’t meet the QA requirements from

  • 0

I have a solution that works, yet it doesn’t meet the QA requirements from the customer. Problem is I can’t control the location of the WebControls, they need to be relative to a chart that is above these. How I see it, I need to “compile” the sb.ToString() into a WebControl, which I’ll then be able to Controls.Add().

I need to go from this working solution:

private void SetTextBoxes()
{
TextBox myBox = new TextBox();
System.Web.UI.WebControls.Label myLabel =
new System.Web.UI.WebControls.Label();

    // <table><tr>
    for (int i = 0; i < _module.Values.Count; i++)
    {
        myLabel = new System.Web.UI.WebControls.Label();
        myLabel.Text = _module.Values[i].Text.ToString() + ": ";

        myBox = new TextBox();
        myBox.BorderStyle = BorderStyle.None;
        myBox.ReadOnly = true;
        myBox.Text = _module.Values[i].Value.ToString("n0");

        myBox.Columns = myBox.Text.Length;

        // <td align="center">
        Controls.Add(myLabel);
        Controls.Add(myBox);
        // </td>
    }
    // </tr></table>
}

Key is the Controls.Add() as it ties into a modular system covering this code and a few other WebControls.

I have a suggestion to what the solution may look like.

private string WriteHtml()
{
    StringBuilder sb = new StringBuilder();
    using (StringWriter stringWriter = new StringWriter(sb))
    {
        using (HtmlTextWriter htmlTextWriter = new HtmlTextWriter(stringWriter))
        {
            htmlTextWriter.RenderBeginTag(HtmlTextWriterTag.Table);
            htmlTextWriter.RenderBeginTag(HtmlTextWriterTag.Tr);

            for (int i = 0; i < _module.Values.Count; i++)
            {
                htmlTextWriter.RenderBeginTag(HtmlTextWriterTag.Td);

                htmlTextWriter.Write(string.Format("{0}: {1:n0}"
                    , _module.Values[i].Text
                    , _module.Values[i].Value));

                htmlTextWriter.RenderEndTag(); // td
            }
            htmlTextWriter.RenderEndTag(); // tr
            htmlTextWriter.RenderEndTag(); // table
        }
    }

    //Controls.Add(sb.ToString());
    return sb.ToString();
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T12:37:22+00:00Added an answer on May 25, 2026 at 12:37 pm

    I solved almost the same task. Here is my results:

    1) I created small helper method:

       public static void RenderControl(Control control, HtmlTextWriter response)
            {
                var sWriter = new StringWriter();
                var htmlWriter = new HtmlTextWriter(sWriter);
    
                control.RenderControl(htmlWriter);
    
                // Write HTML
                response.WriteLine(sWriter);
                response.Flush();
            }
    

    2) At main code if you want to get rendered Html you are doing somthing like this:

        StringBuilder sb = new StringBuilder();
        using (StringWriter stringWriter = new StringWriter(sb))
        {
            using (HtmlTextWriter htmlTextWriter = new HtmlTextWriter(stringWriter))
            {
              Control control= new YourControlWithTextBox();
              WebControlHelper.RenderControl(control, htmlTextWriter);
              return stringWriter.ToString();
            }
        }
    

    With this implementation you can leave SetTextBoxes() as is. And you get 2 version of same control. Here is 2 huge benefits:
    a)code is still readable and described in asp.net terms.
    b)you can use WebControlHelper.RenderControl everywhere where you need solve simmilar task

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a reporting solution that works like this. User orders the report to
I have a very simple problem and a solution that will work, but I'm
I have a solution that is deployed using ClickOnce. It consists of an application,
I have a solution that contains a good deal of projects, I would like
I have a solution that is missing a lot of code coverage. I need
I have a solution that contains two projects. One project is an ASP.NET Web
I have a solution that is source controlled with Subversion and AnkhSVN in Visual
I have a solution that is being referenced by a MSBuild project. In the
I have a solution that I am trying to build in Visual Studio which
Currently I have solution A that contains a domain layer base and solution B

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.