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

  • Home
  • SEARCH
  • 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 6829235
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:28:37+00:00 2026-05-26T22:28:37+00:00

I am using the below code snippet to get the html string of a

  • 0

I am using the below code snippet to get the html string of a control. This response has a lot of formatting characters like \n, \t, \r for indenting the html. How do i remove this without wihtout affecting formatting of actual text within the controls.

public static string RenderControl( Control control )
{           
            string renderedString;

            using ( TextWriter writer = new StringWriter( ) )
            {
                control.RenderControl( new HtmlTextWriter( writer ) );
                renderedString = writer.ToString( );
            }                   

            return renderedString;
}

For ex-

if i see the response of a table control it looks something like –

<table>\r\n\t\t<tr>\r\n\t\t         
<td>abc\r\n def</td>...</table>

the output i need is –

<table><tr>         
<td>abc\r\n def</td>...</table>
  • 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-26T22:28:38+00:00Added an answer on May 26, 2026 at 10:28 pm

    If the generated markup is XML-compatible, then you could parse the result with an XmlReader or even an XmlDocument instance and use an XmlWriter to rewrite the markup but with XmlWriterSettings set to remove all unnecessary whitespace.

    An alternative (and potentially easier) strategy is described below:

    In XML (and HTML) only single whitespace characters are significant, so you could do a quick and easy fix by putting the generated markup into a regular expression replacement that removes all adjacent whitespace characters (i.e. replace “\s\s+” with “” – ‘\s’ is the .NET Regex symbol for any whitespace character).

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

Sidebar

Related Questions

In the snippet of code below, I'm using a class to get a reference
How to send triimed data using $.get() see code snippet below: $(#txtSearch).keyup(function() { $.get(/controller/method/,
I am using the code snippet below, however it's not working quite as I
I have a small snippet of code below that I'm running using PellesC .
I'm using the following code to get a JSON string that I'm going to
I am currently using the below code to get a list of uuid's then
I am using CodeIgniter Active Record Class to generat tables, my code snippet below.
i am using below code to change the the font type of text view.
Currently i'm using below code which works well. $(#topperAtBaseLevel:visible, #lowerAtBaseLevel:visible, #midAtBaseLevel).hide(); any optimised code?
I am using below code to create a reminder in Google calendar (using Google

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.