本文介绍了动态添加客户端脚本到asp.net页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将JavaScript动态添加到asp.net页面.有人可以指出我的工作榜样吗?我知道可以通过使用 Page.ClientScript.RegisterClientScriptBlock
完成但我不知道要使用它.
I want to add javascript to asp.net page dynamically.can anybody point me towards working example?i know it can be done by using Page.ClientScript.RegisterClientScriptBlock
but i have no idea to use it.
推荐答案
这是MSDN链接
if (!this.Page.ClientScript.IsClientScriptBlockRegistered(typeof(Page), "Utils"))
{
string UtilsScript = ResourceHelper.GetEmbeddedAssemblyResource("Utils.js");
this.Page.ClientScript.RegisterClientScriptBlock(typeof(Page), "Utils", UtilsScript, true);
}
我添加了上面的示例来提供帮助,
I added the above example to help,
在这里,我们测试脚本是否已被注册(使用注册时使用的dkey类型)从嵌入式资源中以字符串形式获取脚本,然后进行注册(最后一个参数true指示代码呈现Script标签).
Here we test if the script is already registered (using the type an dkey we register against) get the script as a string from an embedded resource, then register (the last parameter of true tells the code to render Script tags).
希望这会有所帮助
P
这篇关于动态添加客户端脚本到asp.net页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!