C#String新行

时间:2013-08-01 10:43:43

标签: c# javascript asp.net string

我的Web应用程序中有一个ASPX页面,我正在尝试在字符串中创建一个包含多行的字符串,并将其用于此方法

ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + Message + "');", true);

此代码位于.cs文件中。

我尝试了多种方法将此字符串创建为多行,但似乎它不起作用,我使用了以下方法:

String Message = "Not Authorised to use Sysomos. "+ "<br>" + " Please Email Ian Atkinson for Authorisation";

String Message = "Not Authorised to use Sysomos. "+ Enviroment.NewLine + " Please Email Ian Atkinson for Authorisation";

这两种方法都不起作用。我也尝试了一个字符串生成器而没有运气。

有什么建议吗?

2 个答案:

答案 0 :(得分:4)

试试这个

String Message = "Not Authorised to use Sysomos. \\n Please Email Ian Atkinson for Authorisation";

答案 1 :(得分:3)

您需要将\n字符用于n个新行

alert("Hello \n \n World!");