2

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.

0

3 Answers 3

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.

Sign up to request clarification or add additional context in comments.

Comments

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)

Comments

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;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.