javascript ScriptManager.RegisterStartupScript

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4464075/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-25 13:46:09  来源:igfitidea点击:

ScriptManager.RegisterStartupScript

javascriptasp.net

提问by Donato bruno comunali F. dutra

I have this code:

我有这个代码:

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

where text is a string as I am trying to insert a \nin the text message but does not show any.

其中 text 是一个字符串,因为我试图\n在文本消息中插入 a但没有显示任何内容。

采纳答案by capdragon

Your code text needs two escape thingies.

您的代码文本需要两个转义的东西。

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

use:

利用:

string text = "test \n testing";

Instead of:

代替:

string text = "test \n testing";

回答by Stefan H

The ", True"adds the script tags.

", True"添加脚本标记。

You want GetType(Page)

你要 GetType(Page)