如何创建像w3学校的tryit html? [英] How to create a tryit html like w3 school?

查看:210
本文介绍了如何创建像w3学校的tryit html?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在实现一个用于编写html的文本框和一个用于在用户单击按钮时立即以表单形式显示该html代码输出的表单,例如:

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

任何人都可以用c#在asp中为我提供代码吗?

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

推荐答案

最简单的方法,请参见下文.
不要忘记设置ValidateRequest = false.
对于.NET 4.0,还需要将以下行添加到您的web.config文件中:

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

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







<%@ 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.


你好Sunil,

基思对他说的话绝对是正确的,但是由于我处于典型的周末模式,我将为您提供入门知识:

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>



如果您想自己做一些工作,请像使用w3school示例中那样使用iframe来振作起来. Textareas innerText放入div的innerHtml中.普雷斯托(Presto),不涉及任何魔术.


干杯

Manfred



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


完全可以使用javascript在客户端完成.查看document.write.
It can be done entirely client-side with javascript. Look into document.write.


这篇关于如何创建像w3学校的tryit html?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆