没有Ajax asp.net回发后执行JavaScript函数 [英] Execute javascript function after asp.net postback without Ajax

查看:85
本文介绍了没有Ajax asp.net回发后执行JavaScript函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想与出用ajax asp.net回发后执行JavaScript函数。

我试过在我的方法,甚至没有运气以下内容:

  Page.ClientScript.RegisterStartupScript(的GetType(),ShowPopup,showCheckOutPopIn('Livraison',556););


解决方案

您应该只是使用ScriptManager类,因为Page.ClientScript属性是德precated ...


  

ClientScriptManager类是在ASP.NET 2.0中新的替代用于管理,现在去precated脚本Page类的方法。

  参考:MSDN - Page.ClientScript物业


使用的ScriptManager的优点是,它与异步回发,因此,如果您正在使用AJAX它不会与ClientScriptManager工作。

您code是这样的:

  ScriptManager.RegisterStartupScript(这一点,this.GetType(),ShowPopup,showCheckOutPopIn('Livraison',556);,真正的);

还请注意,如果您正在使用AJAX,并有一段JavaScript代码code,那你想在多个回发执行,那么你应该参考您的UpdatePanel在firstargument例如:

  ScriptManager.RegisterStartupScript(MainUpdatePanel的typeof(串),ShowPopup,showCheckOutPopIn('Livraison',556);,真正的);

I wish to execute a javascript function after asp.net postback with out using ajax.

I've tried the following in my even method with no luck:

Page.ClientScript.RegisterStartupScript(GetType(), "ShowPopup", "showCheckOutPopIn('Livraison',556);");

解决方案

You should rather use the ScriptManager class, since the Page.ClientScript property is deprecated...

The ClientScriptManager class is new in ASP.NET 2.0 and replaces Page class methods for managing scripts that are now deprecated.
Reference: MSDN - Page.ClientScript Property

The advantage with ScriptManager is that it works with asynchronous postbacks, so if you are using AJAX it will not work with the ClientScriptManager.

Your code would look like this:

ScriptManager.RegisterStartupScript(this, this.GetType(), "ShowPopup", "showCheckOutPopIn('Livraison',556);", true);

Note also that if you are using AJAX and have a piece of javascript code, that you want executed on multiple postbacks, then you should refer to your UpdatePanel in the firstargument e.g.:

ScriptManager.RegisterStartupScript(MainUpdatePanel, typeof(string), "ShowPopup", "showCheckOutPopIn('Livraison',556);", true);

这篇关于没有Ajax asp.net回发后执行JavaScript函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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