C# ClientScript.RegisterClientScriptBlock?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1905716/
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-08-06 21:45:31  来源:igfitidea点击:

ClientScript.RegisterClientScriptBlock?

c#asp.netregisterclientscriptblock

提问by Surya sasidhar

In my web application when i upload a video and click the save button, if the video is uploaded i write the code to display the message video is uploaded. My code is as follows:

在我的网络应用程序中,当我上传视频并单击保存按钮时,如果视频已上传,我会编写代码来显示视频已上传的消息。我的代码如下:

ClientScript.RegisterClientScriptBlock(GetType(), "sas", "<script> alert('Inserted successfully');</script>", false);

When the alert box appears is comes with a white background. I clicked on ok button in that alert box but the page is not going back to the previous page it is showing the same white space.

当警告框出现时带有白色背景。我单击了该警报框中的确定按钮,但该页面不会返回上一页,而是显示相同的空白区域。

Can you solve the problem.? If you not understand i will explain clearly.

你能解决问题吗。?如果你不明白我会解释清楚。

In local it is working fine but when i update in online it is not working.

在本地它工作正常,但当我在线更新时它不起作用。

采纳答案by ACP

Hai sridhar, I found an answer for your prob

Hai sridhar,我为您的问题找到了答案

ClientScript.RegisterClientScriptBlock(GetType(), "sas", "<script> alert('Inserted successfully');</script>", true);

change false to true

把假改成真

or try this

或者试试这个

ScriptManager.RegisterClientScriptBlock(ursavebuttonID, typeof(LinkButton or button), "sas", "<script> alert('Inserted successfully');</script>", true);

回答by John K

The method System.Web.UI.Page.RegisterClientScriptBlockhas been deprecatedfor some time (along with the other Page.Register* methods), ever since .NET 2.0 as shown by MSDN.

System.Web.UI.Page.RegisterClientScriptBlock方法已被弃用一段时间(以及其他 Page.Register* 方法),自 .NET 2.0 以来,如 MSDN 所示。

Instead use the .NET 2.0 Page.ClientScript.Register*methods.- (The ClientScript property expresses an instance of the ClientScriptManagerclass )

而是使用 .NET 2.0 Page.ClientScript.Register*方法。-(ClientScript 属性表示ClientScriptManager类的一个实例)

Guessing the problem

猜测问题

If you are saying your JavaScript alert box occurs before the page's content is visibly rendered, and therefore the page remains white (or still unrendered) when the alert box is dismissed by the user, then try using the Page.ClientScript.RegisterStartupScript(..) methodinstead because it runs the given client-side code when the page finishes loading- and its arguments are similar to what you're using already.

如果您说 JavaScript 警报框出现在页面内容可见呈现之前,因此当用户关闭警报框时页面保持白色(或仍未呈现),请尝试使用Page.ClientScript.RegisterStartupScript(.. ) 方法,因为它会在页面完成加载时运行给定的客户端代码- 并且其参数与您已经使用的参数类似。

Also check for general JavaScript errorsin the page - this is often seen by an error icon in the browser's status bar. Sometimes a JavaScript error will hold up or disturb unrelated elements on the page.

还要检查页面中的一般 JavaScript 错误- 这通常通过浏览器状态栏中的错误图标看到。有时 JavaScript 错误会阻止或干扰页面上不相关的元素。

回答by Krishn Y

See if the below helps you:

看看以下内容是否对您有帮助:

I was using the following earlier:

我之前使用过以下内容:

ClientScript.RegisterClientScriptBlock(Page.GetType(), "AlertMsg", "<script language='javascript'>alert('The Web Policy need to be accepted to submit the new assessor information.');</script>");

After implementing AJAX in this page, it stopped working. After reading your blog, I changed the above to:

在此页面中实现 AJAX 后,它停止工作。看了你的博客,我把上面的改成了:

ScriptManager.RegisterClientScriptBlock(imgBtnSubmit, this.GetType(), "AlertMsg", "<script language='javascript'>alert('The Web Policy need to be accepted to submit the new assessor information.');</script>", false);

This is working perfectly fine.

这工作得很好。

(It's .NET 2.0 Framework, I am using)

(这是 .NET 2.0 框架,我正在使用)