我做了新闻发布系统,asp.net(vb),在后台管理页面用到了两个文本框,一个添加标题的,一个添加内容的,在新闻浏览页面用到了两个label控件,分别显示标题和内容,现在碰到的问题是在后台管理也面内容文本框中按一定的格式输入的内容在浏览页面如何也按同样的格式显示!

解决方案 »

  1.   

    没看懂,这段你应该有用
    /// <summary>
      /// 替换html中的特殊字符
      /// </summary>
      /// <param name="theString">需要进行替换的文本。</param>
      /// <returns>替换完的文本。</returns>
      public string HtmlEncode(string theString)
      {
       theString=theString.Replace(">", "&gt;");
       theString=theString.Replace("<", "&lt;");
       theString=theString.Replace(" ", "&nbsp;");
       theString=theString.Replace(" ", "&nbsp;");
       theString=theString.Replace("\"", "&quot;");
       theString=theString.Replace("\'", "&#39;");
       theString=theString.Replace("\n", "<br/> ");
       return theString;
      }
      

  2.   

    最基本的就是输入时把string里的空格,回车换行转成&nbsp;,<br>
    显示时再把库里取的string里的&nbsp;,<br>替换成空格,回车换行。
    如果文章里还有代码,特殊符号等,考虑的情况会多一些,不过与上两
    种是类似的。
      

  3.   

    Me.Server.HtmlEncode(tb.text).Replace(vbCrLf, "<br>")在后台这样添加,试一下
      

  4.   

    应该在后台输入内容的时候用在线编辑器,因为它带格式,如:eWebEditor,FCKeditor.....
    不能用文本框.
    给你一个下载地址: http://www.qdz.cn/?id=137