3

I have ASP.NET web page (mypage.aspx) which has a TextBox (multiline) and a Button.

Problem: I want to add html content into textbox and then click the button, it should generate the exact web page according to my html.

Example:

<html>
<head><title></title></head>
<body>
<h1>Hello</h1>
</body>
</html>

The generated web page should contain Hello.

Any idea..?

Thank in advance.

Shadow The GPT Wizard
  • 66,030
  • 26
  • 140
  • 208
udayalkonline
  • 31
  • 1
  • 2

3 Answers3

1

Take a look in this answer I gave some while ago, in your case have body be txtHTML.Text to take the HTML given by the user.

To make it work you'll have to follow those steps:

  1. Add this under system.web in the web.config file:
    <httpRuntime requestValidationMode="2.0" />
  2. Add this to the Page directive in the .aspx file:
    validateRequest="false"

Otherwise you won't be able to send raw HTML contents.

Community
  • 1
  • 1
Shadow The GPT Wizard
  • 66,030
  • 26
  • 140
  • 208
0

Use a html editor like tincymce instead of a textbox. Save the content of the html editor in a database and call it with another page. Or post the content on button press and display it on postback (and hide the textbox + button)

Ivo
  • 3,406
  • 4
  • 33
  • 56
0

This sounds like quite a simple HelloWorld type app? Though you'll need to protect against injections if this is a public app (maybe HTMLEncoding and decoding). But Basically (I'm assuming webforms for the textbox, but it can easily be changed for MVC):

This would go in your page:

In your codebehind (just in the Page_Load method): string content = HtmlContent.Text;

You can then do what you need to with the content variable. If you are just outputting to the same page add:

to your page

and change your codebehind from: string content = HtmlContent.Text;

to Output.Text = HtmlContent.Text;

Francis Gilbert
  • 3,382
  • 2
  • 22
  • 27