1

What is a good way to redirect console output to asp.net Text-box on Web page? If I have an existing program that has console.Write , do I need to overload the function in Web page Text-box.I have TextBox on web page and I Want to display console.Write output in TextBox. Thank You.

Valar_Dohaeris
  • 53
  • 1
  • 1
  • 8
  • Possible duplicate of [How to use Console.WriteLine in ASP.NET (C#) during debug?](http://stackoverflow.com/questions/9614218/how-to-use-console-writeline-in-asp-net-c-during-debug) – Peter B Jan 25 '17 at 10:03
  • 1
    To summarize the duplicate: it can't be used in ASP.NET, slightly similar functionality can only be achieved using `Debug.Write` or (if you don't mind that your HTML output gets mangled) `Response.Write`. – Peter B Jan 25 '17 at 10:05

2 Answers2

1

Console.Write is used to put output on a console. I will not work in Asp.Net. Asp.Net text box control text can be set like textBoxName.Text = "some value".

If you would like to write some text to Asp.Net response stream, you may use Response.Write.

FIre Panda
  • 6,537
  • 2
  • 25
  • 38
0
public class CustomWriter : TextWriter
{
    public override void WriteLine(string value)
    {
        textBox1.Text += value + Environment.NewLine
    }

    // ... etc.
}

And use it like this:

Console.SetOut(new CustomWriter());
György Kőszeg
  • 17,093
  • 6
  • 37
  • 65