如何从 C# 调用 Jquery
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17280415/
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
How to Call Jquery from C#
提问by omixam
I've tried to call the dialog-model jqueryui
我试图调用对话框模型 jqueryui
$(function () {
$("#dialog-modal").dialog({
modal: true
});
});
from C# using
从 C# 使用
ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "dialog();", true);
but the JQuery is executing after page load and not when I call the ScriptManager.
但 JQuery 在页面加载后执行,而不是在我调用 ScriptManager 时执行。
How can I do that the JQuery function execute when the ScriptManager.RegisterStartupScriptit execute in C#?
当ScriptManager.RegisterStartupScript在 C# 中执行时,如何执行 JQuery 函数?
Apparently I did not explain well: This jquery I call during postback when execute especific function, but is executting in the first postback. I want call the jquery during the code execution. Should be more specific?
显然我没有很好地解释:这个 jquery 我在执行特定函数时在回发期间调用,但在第一次回发中执行。我想在代码执行期间调用 jquery。应该更具体吗?
采纳答案by Michael
C#:
ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "showMyDialog();", true);
Javascript:
<script>
function showMyDialog() {
$("#dialog-modal").dialog({
modal: true
});
</script>
回答by Peter Rasmussen
Javascript is executed after the page is rendered. It cannot "call" or "run" c# code, unless you make a post/get to your webserver (which the server side handles).
Javascript 在页面呈现后执行。它不能“调用”或“运行”c# 代码,除非您发布/获取您的网络服务器(服务器端处理)。
c# is run on the server and javascript on the client.
c# 在服务器上运行,javascript 在客户端运行。

