调用Java脚本提示功能,当整个ASP.Net页面获取负载 [英] Calling Java Script Alert Function when entire ASP.Net Page gets load

查看:91
本文介绍了调用Java脚本提示功能,当整个ASP.Net页面获取负载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我ASP.net4.0 code使用javascipt的报警功能背后的文件内容页

I used JavaScipt Alert function in ASP.net4.0 code behind file of content Page

public void Show(string message)
 {

  Page.RegisterClientScript(this.GetType(), "Alert", "<script type=text/javascript>alert('+message+')</script>");         
 }

当我在点击链接来获得这个脚本调用随后警报消息黑屏然后来到同一屏幕被满载。

When i click on button to get this script call then the alert message came on blank screen then the same screen gets loaded fully.

我要加载整个页面后,此消息(MSG将得到显示同一页面上背部的控制),然后味精显示。
使用母版页和内容页。

I want this message after loading the whole page(Msg will get displayed on same page with back controls) and then msg is displayed. Using Master Pages and content Pages..

请在

推荐答案

如果你想显示在文档加载时,使用的 的RegisterStartupScript

If you want to show it when the document is loaded, use RegisterStartupScript:

 public void Show(string message)
 {
     ClientScriptManager cs = Page.ClientScript;
     Type myType = this.GetType();
     // Check to see if the startup script is already registered.
     if (!cs.IsStartupScriptRegistered(myType, "AlertScript"))
     {
         String script = "alert('" + cleanMessage + "')";
         cs.RegisterStartupScript(myType, "AlertScript", script, true);
     }
 }

的RegisterStartupScript 在页面中的所有元素后,会使你的脚本,这将确保它运行其他的DOM元素被加载后。

RegisterStartupScript will render your script after all the elements in the page, this will ensure that it runs after the other DOM elements are loaded.

这篇关于调用Java脚本提示功能,当整个ASP.Net页面获取负载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆