急!做论坛时发表的一个帖子的内容是有换行的,可是显示时却没有了是怎么回事?
在发表时,提交按钮的事件里是这样的:
string cont = Server.HtmlEncode(tbContent.Text.ToString().Replace( " ' ", "! "));-------------cont是发表的内容;
在显示位置绑定时是这样的:
<asp:Label ID= "Label4 " runat= "server " Text= ' <%# Server.HtmlDecode(Eval( "content ").ToString()) %> '> </asp:Label>
但是,在发表时,明明是有换行的,到了显示的地方却都在一行了!这是怎么回事啊?
拜托各位了!!
[解决办法]
public static string FullHTMLEncode(string inputVal)
{
if(inputVal != null)
{
inputVal = inputVal.Replace( "> ", "> ");
inputVal = inputVal.Replace( " < ", "< ");
inputVal = inputVal.Replace( "\ ' ", "' ");
inputVal = inputVal.Replace( "\ " ", "" ");
inputVal = inputVal.Replace(string.Format( "{0} ",(char)32), " ");
inputVal = inputVal.Replace(string.Format( "{0} ",(char)9), " ");
inputVal = inputVal.Replace(string.Format( "{0} ",(char)34), "" ");
inputVal = inputVal.Replace(string.Format( "{0} ",(char)39), "' ");
inputVal = inputVal.Replace(string.Format( "{0} ",(char)13), " ");
inputVal = inputVal.Replace(string.Format( "{0} ",(char)10)+string.Format( "{0} ",(char)13), " </p> <p> ");
inputVal = inputVal.Replace(string.Format( "{0} ",(char)10), " <br/> ");
}
return inputVal;
}
把字符用以上函数进行Html编码就可以了。