如何写在code在asp.net中的JavaScript背后使用C# [英] how to write javascript in asp.net in code behind using C#
问题描述
问候,
我怎么能写在asp.net中的JavaScript code在code后面使用C#。
例如,
我点击按钮的事件,当我按一下按钮我想调用该Java脚本code:
Greetings, how can I write JavaScript code in asp.net in code behind using C#. For example, I have click button event when I click the button I want to invoke this java script code:
alert("You pressed Me!");
我想知道如何使用Java脚本从code的后面。
I want to know how to use java script from code behind.
感谢您;
推荐答案
其实,这是你所需要的:
Actually, this is what you need:
string myScriptValue = "function callMe() {alert('You pressed Me!'); }";
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "myScriptName", myScriptValue, true);
所有的javascript复制到字符串,然后将它注册到你的aspx页面在code-后面。然后在aspx页面,你可以只要你想调用JavaScript函数。你应该写在C#页面Page_Load方法这code。
Copy all of javascript into string and then register it into your aspx page in code-behind. Then in aspx page, you can call the javascript function whenever you want. You should write this code in Page_Load method in C# page.
这篇关于如何写在code在asp.net中的JavaScript背后使用C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!