Line break in popup

I am trying to add a new Javascript message for a string. I tried "\ n" and "Environment.NewLine". I get an Unterminated string constant error. Could you tell me what could be the problem? I appreciate any help. I also tried \ r \ n.

string msg = "Your session will expire in 10 minutes. \n Please save your work to avoid this.";


if (!this.ClientScript.IsStartupScriptRegistered(ID)) 
   this.ClientScript.RegisterStartupScript(GetType(), ID, String.Format("<script language=JavaScript>setTimeout(\'alert(\"{1}\");\',{0}*1000);</script>", sTime, msg));
+5
source share
6 answers

I suspect you need to change your code:

string msg = "Your session will expire in 10 minutes. \\n Please save your work to avoid this.";

And exit \n, otherwise the output code will actually include a line break, not\n

Your output code will look like this:

setTimeout('alert("Your Session....
 Please save your work to ....");', 1000);

Instead

setTimeout('alert("Your Session....\n Please save your work to ....");', 1000);
+14
source

I'm not sure, but I think that \ n is hiding in the string.Format method, like \. Perhaps you should use \\ n instead.

: \\\n , . xD

+3

, , ' . , .

+2

"@" - :

string msg = @"Your session ....";
0

, , , ', JS. Javascript JSON, # "" JS.

JSON go-to JS- SQL-.

0

Adding @at the beginning should help.

0
source

All Articles