如何使用C#在asp.net中的html编辑器中编辑HTML页面(模板) [英] How to Edit Html page ( Template ) in html Editor in asp.net with C#

查看:132
本文介绍了如何使用C#在asp.net中的html编辑器中编辑HTML页面(模板)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在varchar(Max)数据类型中的MS Sql Server中保存html页面(Template),这工作正常,但是当我想在HTML Editor中编辑这些Template时,显示为代码页,但我希望将模板显示为设计方式.


如果您有任何想法,请解决我的问题.

给我一个参考链接




感谢's

I am save html page ( Template ) in MS Sql Server in varchar(Max) datatype this is working properly but when i want to edit these Template in HTML Editor is show as a code pages but i want to show template as a design way.


If u have any Idea Please resolve my problem.

Give me a reference link




Thank''s

推荐答案

之后,从数据库中读取html代码并更改了代码,必须从html代码中进行渲染才能看到新的设计.
为此,请在asp.net中创建一个SUPER CLASS或USER CONTROL并覆盖Render事件.
在渲染事件"中,编写新的html代码,然后将新的用户控件放入表单中.
示例就像下面的代码:

1.在Default.aspx设计中编写以下代码:

after that read html code from database and changed your code,you must take render from your html code to see the new design.
for this work, create a SUPER CLASS or USER CONTROL in asp.net and override the Render event .
in the Render Event write the new html code , then put the new user control in your form.
example is like below code:

1.in design of Default.aspx write below code:

<div>
        <table style="width: 100%;">
            <tr>
                <td>
                    <h3>
                        old HTML Code</h3>
                </td>
            </tr>
            <tr>
                <td>
                    <button>
                        <span>Your text</span></button>
                </td>
            </tr>
            <tr>
                <td>
                    <h3>
                        new HTML Code</h3>
                </td>
            </tr>
            <tr>
                <td>
                    <uc1:WebUserControl ID="WebUserControl1" runat="server" />
                </td>
            </tr>
        </table>
    </div>





2.创建新的用户控件
在解决方案中的项目名称上,按鼠标右键,然后选择添加新项"
然后选择WebUserControl

3.在WebUserControl1.ascx后面的代码中 覆盖渲染事件并采用新的html代码:





2.create new user control
on name of project in the solution press right click then select Add New Item
then select WebUserControl

3.in code behind of WebUserControl1.ascx
overrid render event and take a new html code:

protected override void Render(HtmlTextWriter writer)
  {
      string changedHtmlCode = " <button class=\"rounded\"><span>Your text</span></button>";
      writer.Write(changedHtmlCode);
      base.Render(writer);
  }




4.在Default.aspx设计代码中的HEAD标记之前编写此代码:




4.write this code before HEAD tag in Default.aspx design code:

<![CDATA[<%@ Register Src="WebUserControl.ascx" TagName="WebUserControl" TagPrefix="uc1" %>]]>



5.完成


default.aspx的所有设计代码如下:



5.finish


all design code of default.aspx is like this:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<%@ Register Src="WebUserControl.ascx" TagName="WebUserControl" TagPrefix="uc1" %>
<!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>Untitled Page</title>
    <link href="./style.css" rel="stylesheet" type="text/css"/>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <table style="width: 100%;">
            <tr>
                <td>
                    <h3>
                        old HTML Code</h3>
                </td>
            </tr>
            <tr>
                <td>
                    <button>
                        <span>Your text</span></button>
                </td>
            </tr>
            <tr>
                <td>
                    <h3>
                        new HTML Code</h3>
                </td>
            </tr>
            <tr>
                <td>
                    <uc1:WebUserControl ID="WebUserControl1" runat="server" />
                </td>
            </tr>
        </table>
    </div>
    </form>
</body>
</html>






后面的所有webUsercontrol代码如下:






and all webUsercontrol code behind is like this:

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class WebUserControl : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected override void Render(HtmlTextWriter writer)
    {
        string changedHtmlCode = " <button class=\"rounded\"><span>Your text</span></button>";
        writer.Write(changedHtmlCode);
        base.Render(writer);
    }


}




我将此示例发送到CODE PROJECT.您可以下载代码项目的源代码.




i send this example to CODE PROJECT. you can download source of code project.



您必须先对内容进行解码,然后再将其放入编辑器中.当您从数据库中读取HTML内容的简单文本时,必须将该简单文本解码为HTML,以便编辑器将其识别为HTML.请说一下AJAX控件工具包HTML编辑器是HTMLEditor1,然后
Hi,
you have to decode the content before putting that into editor.When you read the HTML content from database its a simple text you have to decode that simple text to HTML so that the editor recognize it as a HTML.Say your AJAX control toolkit HTML editor is HTMLEditor1, then
HTMLEditor1.Content=Server.HtmlDecode("CONTENT_FROM_DB")


希望这能解决您的问题.


Hope this will solve your issue.


这篇关于如何使用C#在asp.net中的html编辑器中编辑HTML页面(模板)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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