如何仅在pageload上调用asp.net pageload事件中的javascript函数 [英] How to call javascript function in asp.net pageload event only on pageload

查看:119
本文介绍了如何仅在pageload上调用asp.net pageload事件中的javascript函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何仅在pageload上调用asp.net pageload事件中的javascript函数



i尝试过它,我得到了输出但是它是一直执行,这意味着当我点击按钮时它会被执行,这样如果有任何身体告诉我如何只在页面上执行该功能一次



i使用此代码

How to call javascript function in asp.net pageload event only on pageload

i tried it, i got the output but it is executed on all the time that means when i click the button it gets executed so that if any body tell how can i execute that function only once on pageload

i used this code

<body  onload="Return myfunction();"

推荐答案

window.onload = function()
                {
                   Function();
                };






我假设您正在使用AJAX控件您的页面,

您可以在page_load事件中使用SCRIPTMANAGER控件来调用您的JAVASCRIPT函数,例如



Hi,

I assume you are using AJAX control in your page,
you can call your JAVASCRIPT function by using SCRIPTMANAGER control in your page_load event like

if(!ispostback)
{
 ScriptManager.RegisterStartupScript(this, this.GetType(), "KeyClient", "<script>return myFunction();;</Script>", false);
}



if (!IsPostBack)
  
{
          
ddlTaskLevel.Attributes.Add("onchange", "javascript:return function()"); 
} // for example i took a drop down box. 





将此放在页面加载后面的代码中。



place this in page load in code behind.


这篇关于如何仅在pageload上调用asp.net pageload事件中的javascript函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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