开发者

<br/> not being displayed on text string replacement and then put into placeholder

When I read in the data from SQL it has \r\n for the carriage returns, so I use .Replace to convert the \r\n's to <br/>'s but on display the <br/>'s are ignored. It works if I replace the \r\n's with <p></p> but this is not what I need.

The <br/>'s are being ignored and I n开发者_Go百科eed them to produce a newline.

Any insight as to why it is doing this or how to achieve what I am looking to do would be great!

EDIT: I've addressed the typo in the code below - but that isn't my question -at all-. I've asked about BR's and them displaying.

HTML

<asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>

CODE-BEHIND

string strTempDetail = myReader["Detail"].ToString();
string strMoreTempDetail = strTempDetail.Replace("\r\n", "<br/>");
LiteralControl UserControlSpecialOffers = new LiteralControl(strMoreTempDetail.ToString());
PlaceHolder1.Controls.Add(UserControlSpecialOffers);

Thanks!


You have a typo in your code. You are assigning the original string into your control instead of the string containing your replacements.

change

LiteralControl UserControlSpecialOffers = new LiteralControl(strTempDetail.ToString());

to

LiteralControl UserControlSpecialOffers = new LiteralControl(strMoreTempDetail );


Because you're adding strTempDetail to your literal control, not strMoreTempDetail, which is the string where you performed the replacement.


You have the wrong string in this line

LiteralControl UserControlSpecialOffers = new LiteralControl(strTempDetail.ToString()); 

it should be

LiteralControl UserControlSpecialOffers = new LiteralControl(strMoreTempDetail); 


Are you by any change reading your string from SQL Server? If had issues where a string read from an SQL server ntext column contained a '\n' instead of '\r\n' (even though '\r\n' was saved).

Try if string strMoreTempDetail = strTempDetail.Replace("\n", "<br/>") provides better results.

Or to be on the save side, replace both: string strMoreTempDetail = strTempDetail.Replace("\r\n", "<br/>").Replace("\n", "<br/>")


Someone else had modified the css file and put BR display:none; in the CSS. Of all the places!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜