如何从位于另一个asp.net页面的asp.net c#页面调用javascript函数? [英] how to call a javascript function from asp.net c# page located in another asp.net page?

查看:96
本文介绍了如何从位于另一个asp.net页面的asp.net c#页面调用javascript函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从第一页的代码后面的2个asp.net页面调用第二个asp.net页面中的javascript函数。任何例子?

I have 2 asp.net pages I want from code behind of the first page to call a javascript function in the second asp.net page. any examples?

推荐答案

你制作第一个外部javascript文件。并在页面上调用此文件。

是这样的:

< script type =text / javascriptsrc =../ page / file.js>< / script>

Ex。



代码背后

You make first External javascript file. And call this file on page .
like this:
<script type="text/javascript" src="../page/file.js"></script>
Ex.

Code Behind
protected void DoSomethingButton_Click(object sender, EventArgs e)
{ScriptManager.RegisterStartupScript(this, Page.GetType(), "key", "MyFunc()", true);
}


据我所知,这是正常语法无法实现的,但你可以做一件事。

1.为Javascript代码创建单独的js文件

2.在两个aspx文件中引用该文件

As far as I know, this is not possible with normal syntax but you can do one thing.
1. Create a separate js file for Javascript code
2. Give reference to that file in both the aspx files
<script src="yourscript.js"></script>



3.现在您可以使用js中包含的所有功能文件



从后面的代码调用Javascript函数:


3. Now you can all the functions contained in the js file

To call Javascript function fro code behind :

Page.ClientScript.RegisterStartupScript(this.GetType(), "Script", "YourJSFunction();", true);





希望,它有助于:)



Hopefully, it helps :)


这篇关于如何从位于另一个asp.net页面的asp.net c#页面调用javascript函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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