ScriptManager.RegisterStartupScript

I have this code:

ScriptManager.RegisterStartupScript(this, GetType(), "alert", "alert('Ouve algum problema nos itens " + text + "');", true); 

where the text is a string, as I am trying to insert \ninto a text message, but not displayed.

+3
source share
2 answers

The code needs two things to escape.

string text = "test \\n testing";
ScriptManager.RegisterStartupScript(this, GetType(), "alert", "alert('Ouve algum problema nos itens " + text + "');", true); 

using:

string text = "test \\n testing";

Instead:

string text = "test \n testing";
+3
source

", True" adds script tags.

Do you want to GetType(Page)

0
source

Source: https://habr.com/ru/post/1780737/


All Articles