0

这是我的 aspx.cs 代码:

string script = "alert('Dosya/Dosyalar Başarı İle Yüklendi\n " + btnUpload.FileName + " ');";
ClientScript.RegisterClientScriptBlock(this.GetType(), "Alert", script, true);

但它不起作用。(没有错误)当我删除\n运算符时,它的工作警报功能。我想查看文本下方的文件名

我怎样才能做到这一点?

4

2 回答 2

1

尝试 \r\n 换行:

string script = "alert('Dosya/Dosyalar Başarı İle Yüklendi \\r\\n " + btnUpload.FileName + " ');";
ClientScript.RegisterClientScriptBlock(this.GetType(), "Alert", script, true);

Jon Skeet 早在 2004 年的C# 转义序列中

C# defines the following character escape sequences:

\' - single quote, needed for character literals
\" - double quote, needed for string literals
\\ - backslash
\0 - Unicode character 0
\a - Alert (character 7)
\b - Backspace (character 8)
\f - Form feed (character 12)
\n - New line (character 10)
\r - Carriage return (character 13)
\t - Horizontal tab (character 9)
\v - Vertical quote (character 11)
\uxxxx - Unicode escape sequence for character with hex value xxxx
\xn[n][n][n] - Unicode escape sequence for character with hex value nnnn (variable length version of \uxxxx)
\Uxxxxxxxx - Unicode escape sequence for character with hex value xxxxxxxx (for generating surrogates)
于 2013-09-18T08:32:50.723 回答
0

您可以使用System.Environment.NewLine\n 来代替。例子:

string script = "alert('Dosya/Dosyalar Başarı İle Yüklendi "+ System.Environment.NewLine + btnUpload.FileName + " ');";
ClientScript.RegisterClientScriptBlock(this.GetType(), "Alert", script, true);
于 2013-09-18T08:29:10.197 回答