AJAX方法调用中的RegisterClientScriptBlock [英] RegisterClientScriptBlock within AJAX method call

查看:162
本文介绍了AJAX方法调用中的RegisterClientScriptBlock的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在那个只能通过AJAX调用名为方法的RegisterClientScriptBlock。它不会出现实际上页面上注册脚本,我猜这是因为它实际上没有重新加载整个页面。有没有办法从一个Ajax方法调用中注册页面上的JavaScript?

 保护无效的MyMethod(对象发件人,EventArgs的发送)
{
//此方法只通过AJAX调用称为Page.ClientScript.RegisterClientScriptBlock(Page.GetType(),调整,警报('这里');,真正的);
}


解决方案

使用AJAX启用页面,你应该使用的ScriptManager注册脚本:

  ScriptManager.RegisterClientScriptBlock(页的typeof(我的页面)
    的MyScript,GoStuff(),真)

您可以用它来注册所有的脚本(原载,回传,回传AJAX)。

I am trying to RegisterClientScriptBlock in a method that is only called via an AJAX call. It doesn't appear to actually register the script on the page and I'm guessing this is because it's not actually reloading the entire page. Is there any way to register javascript on a page from within an ajax method call?

	protected void MyMethod(object sender, EventArgs e)
	{
		// This method only called via AJAX call

		Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "resize", "alert('here');", true);
	}

解决方案

With AJAX enabled pages, you should use the ScriptManager to register scripts:

ScriptManager.RegisterClientScriptBlock(Page, typeof(MyPage), 
    "MyScript", "GoStuff()", true)

You can use this to register all your scripts (Original load, postback, AJAX postback).

这篇关于AJAX方法调用中的RegisterClientScriptBlock的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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