从 C# web 应用程序后面的代码调用 javascript 函数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19295559/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 15:02:38  来源:igfitidea点击:

call javascript function from code behind C# web application

javascriptasp.nettelerikrad-controls

提问by Sivajith

i have a javascript function say 'onclientclicking'.

我有一个 javascript 函数说 'onclientclicking'。

  <script type="text/javascript">
        function OnClientClicking(button, args) {
            window.location = button.get_navigateUrl();
            args.set_cancel(true);
        }
    </script>

I want to execute this function from code behind. What i am trying to do is based on certain conditions, i need to set the event to telerik button

我想从后面的代码中执行这个函数。我想做的是基于某些条件,我需要将事件设置为 Telerik 按钮

rad_btn_text.Attributes["OnClientClicking"] = javascript function;

how can it be possible?

怎么可能?

regards,

问候,

Sivajith S

西瓦吉斯

回答by Giulio Caccin

please try this:

请试试这个:

rad_btn_text.OnClientClicking = "OnClientClicking";

It's working on my machine?

它在我的机器上工作吗?

回答by brykneval

rad_btn_text.Attributes.Add("onclick", "OnClientClicking()")

Hopefully this works for you

希望这对你有用

回答by andleer

You can't "call" client side javascript from the server. That said, you can wire up client side events and emit client side code.

您不能从服务器“调用”客户端 javascript。也就是说,您可以连接客户端事件并发出客户端代码。

I don't use telrik controls but the asp.net property is onclientclick. Not sure if that is the same on a telerik control and the client side event is onclick.

我不使用 telrik 控件,但 asp.net 属性是 onclientclick。不确定在 Telerik 控件上是否相同,并且客户端事件是 onclick。

回答by Somnath Kharat

To call the javascript function from server side:

从服务器端调用 javascript 函数:

ScriptManager.RegisterStartupScript(this, typeof(Page), "OnClientClicking", "OnClientClicking();", True);

References

参考

回答by sino

try this. when user click on button the function of "OnClientClicking" will be executed :

试试这个。当用户点击按钮时,“OnClientClicking”的功能将被执行:

rad_btn_text.Attributes["onclick"] = "OnClientClicking()";