简体   繁体   English

是否可以在asp.net中的页面加载事件中调用javascript函数?

[英]Is it possible to call javascript function to the pageload event in asp.net?

Suppose i have created one .js file name as: MyNoteBook.js. 假设我创建了一个.js文件名:MyNoteBook.js。 In this .js file i have written function as name count(). 在这个.js文件中,我编写了名为count()的函数。 Now I am creating MyNoteBook.aspx page in asp.net. 现在,我在asp.net中创建MyNoteBook.aspx页面。 On the event of pageload of .aspx file, i want to call that count() function of that .js file. .aspx文件的页面加载时,我想调用该.js文件的count()函数。 Is it is possible, If yes then please tell me. 是否可以,如果可以,请告诉我。

If no, then how i can write count function in .aspx page? 如果没有,那么我如何在.aspx页中编写计数函数?

To call a JS function on page load, make sure there is an onLoad attribute on the body tag that calls it: 要在页面加载时调用JS函数,请确保在body标记上有一个调用它的onLoad属性:

<body onLoad="count();">

This all happens client side , as Javascript runs in the browser. 这一切都发生在客户端 ,因为Javascript在浏览器中运行。

You can't call a client side function from server side code. 您不能从服务器端代码调用客户端函数。


As for writing the function server side - without knowing what it does, no one can tell you how to convert it to server side code. 至于编写功能服务器端-不知道它做什么,没人能告诉您如何将其转换为服务器端代码。

you could use ClientScriptManager.RegisterStartupScript 您可以使用ClientScriptManager.RegisterStartupScript

have a look at: 看一下:

http://msdn.microsoft.com/en-us/library/z9h4dk8y(v=VS.90).aspx http://msdn.microsoft.com/en-us/library/z9h4dk8y(v=VS.90).aspx

One possibility is to use the javascript pageLoad function from the ASP.NET Ajax framework. 一种可能性是使用ASP.NET Ajax框架中的javascript pageLoad函数。 You can find more information about the ajax client-side life-cycle events here . 您可以在此处找到有关ajax客户端生命周期事件的更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM