如何从代码后面调用javascript函数调用另一个代码隐藏方法 [英] How to call javascript function from code behind which calls another code behind method

查看:53
本文介绍了如何从代码后面调用javascript函数调用另一个代码隐藏方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个调用代码隐藏方法的javascript函数。我从页面加载函数后面的代码调用javascript函数。当我在页面加载时调用javascipt函数时,它不会调用后面的代码方法。但是当我用1或2秒延迟调用javscript函数时,它将调用代码隐藏方法。有没有办法解决上述问题。

来自代码:ScriptManager.RegisterStartupScript(this.Page,this.GetType(),test,clk0();,true);

来自Javascript:

 function clk0(){
var Btninfo0 = document.getElementById(< span class =code-string>' btnreassign');
Btninfo0.click();
}



javascript函数假设在后面的代码中调用btn_click函数

解决方案

你可以调用使用ClientScript.RegisterStartupScript()方法从代码隐藏文件中获取javascript函数,该方法接受三个参数。



示例:



  function 验证(msg)
{
alert(msg);
}







从代码隐藏文件调用函数。



 受保护  void  Button1_Click(  object  sender,EventArgs e)
{
ClientScript.RegisterStartupScript( this .GetType (), AnyName javascript:validate('Hello') true );
}





您可以参考以下关于ClientScript.RegisterStartupScript()方法的链接。

http://msdn.microsoft.com/en- us / library / z9h4dk8y.aspx [ ^ ]


I have one javascript function which call the code behind method. I am calling that javascript function from code behind on page load function. When I call the javascipt function on page load, its not calling the code behind method. But when I call javscript function with 1 or 2secs delay, it will call code behind method. Is there any ways to solve the above issue.
From code behind: ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "test", "clk0();", true);
From Javascript:

function clk0() {
             var Btninfo0 = document.getElementById('btnreassign');
             Btninfo0.click();
         }


javascript function suppose to call btn_click function in code behind

解决方案

You can call the javascript function from code behind file using ClientScript.RegisterStartupScript() method which accepts three parameters.

Example:

function Validate(msg)
{
   alert(msg);
}




Calling The function from code behind file.

protected void Button1_Click(object sender,EventArgs e)
{
   ClientScript.RegisterStartupScript(this.GetType(),"AnyName","javascript: validate('Hello')",true);
}



You can refer the following link about the method ClientScript.RegisterStartupScript().
http://msdn.microsoft.com/en-us/library/z9h4dk8y.aspx[^]


这篇关于如何从代码后面调用javascript函数调用另一个代码隐藏方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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