Click here to Skip to main content
15,888,610 members
Please Sign up or sign in to vote.
1.00/5 (10 votes)
See more:
Hi I am implementing a textbox for writing html and a form for displaying output of that html code in a form instantly as the user click on button for example:

http://w3schools.com/html/tryit.asp?filename=tryhtml_paragraphs1

Can any one provide me code in asp with c# please
Posted
Updated 21-Nov-10 1:27am
v2
Comments
Keith Barrow 21-Nov-10 7:27am    
My Vote of 1: You haven't tried anything, just stated your requirements, then asked for the solution.
Richard MacCutchan 21-Nov-10 7:33am    
Hint: go to the link you provided above and try right-clicking your mouse on it. You may be surprised at what you see.
[no name] 21-Nov-10 7:44am    
Keith Barrow Nobody asked u to vote. Dont u have any job to do? hw can u day i havnt tried anything?
Manfred Rudolf Bihy 21-Nov-10 8:18am    
Well he surely can say that. You haven't provided us with any information what you've tried, so we'll have to assume it was zilch, zero, nada (insert your favorite for nothing here). Besides that voting on questions and answers is what makes this whole CP stuff work. If you expect to be receiving anwsers here you'd better change your attitude. (Feeling tempted to remove / empty my answer right now) ;)
Keith Barrow 21-Nov-10 11:16am    
Yes, I have a job. I lecture at a university, having spent the last ten years as a programmer at various large and prestigious companies. If I want to vote, that's my business, not yours. If you don't want to be voted down, I suggest you write questions according to the site guidelines. You'll notice other comments similar to mine.

The simplest way to do it, see below.
Don't forget to set ValidateRequest=false.
For .NET 4.0 it also needed to add into your web.config file the following line

XML
<system.web>
      <httpRuntime requestValidationMode="2.0" />
        <compilation debug="true" targetFramework="4.0" />
    </system.web>



XML
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="CodeProjectWeb.WebForm1"
    ValidateRequest="false" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <table>
            <tr>
                <td>
                    <asp:Button ID="btnClick" runat="server" Text="show" OnClick="btnClick_Click" /><br />
                    <asp:TextBox runat="server" ID="txtText" TextMode="MultiLine" Rows="5" Columns="50"></asp:TextBox>
                </td>
                <td valign="top">
                    <%if (this.IsPostBack) { Response.Write(Server.HtmlDecode((txtText.Text))); } %>
                </td>
            </tr>
        </table>
    </div>
    </form>
</body>
</html>


Good luck.
 
Share this answer
 
Comments
[no name] 21-Nov-10 12:21pm    
thank you:)
Hello Sunil,

Keith is absolutely right with what he said, but since I'm in my typical mellow weekend mode I'll let you have this for starters:

<html lang="en-US" xml:lang="en-US" xmlns="http://www.w3.org/1999/xhtml">
	<head>
	    <title>Quick shot</title>
    </head>
	<body>
		<input style="margin-bottom:5px;font-family:verdana;" name="submit" type="submit" value="Edit and Click Me >>" onclick="doDisplay()">
		<textarea id="sourceCode" style="width:400px; height: 300px" name="code" wrap="logical" orows="21" ocols="42">
			<p>This is a paragraph.</p>
			<p>This is a paragraph.</p>
			<p>This is a paragraph.</p>
		</textarea>
		Your Result:
		<div id="displayHtml" style="width: 500px; height: 500px; border: 2px solid red;">
		</div>
	</body>
	<script type="text/javascript">
		function doDisplay()
		{
			var destination = document.getElementById("displayHtml");
			var sourceCode = document.getElementById("sourceCode").innerText;
			alert(sourceCode);
			destination.innerHTML = sourceCode;
		}
	</script>
</html>


If you want to do some work yourself, go pep it up to use iframes like in the w3school sample. Textareas innerText is put into the div's innerHtml. Presto, no magic involved.


Cheers

Manfred
 
Share this answer
 
v6
Comments
[no name] 21-Nov-10 8:23am    
thank you for the sol.
It can be done entirely client-side with javascript. Look into document.write.
 
Share this answer
 
Comments
Manfred Rudolf Bihy 21-Nov-10 8:14am    
No need for document.write, look at my sample above :) .
LloydA111 21-Nov-10 9:24am    
Document.write means there is no extra load on the server, theres no need for something like this to run on the server unless you really want it to.
Manfred Rudolf Bihy 21-Nov-10 9:28am    
Hmm, you've probably not looked at my solution, considering your comment. My solution works purely by utilizing good ol' javascript and nothin' more :) You must be talking about Ed's sample.
LloydA111 21-Nov-10 9:29am    
Oops yes I was :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900