如何调用asp.net web应用程序的JavaScript方法 [英] How to call javascript method in asp.net web application
问题描述
我想用一个C#函数中的JavaScript函数
I want to use a javascript function inside a c# function
protected void button1_Click(object sender,EventArgs e){
//javascript function call ex.
/*
boolean b=the return of:
<script type="text/javascript">
function update() {
var result = confirm("Do you want to delimit the record?")
if (result) {return true;}
else {
return false;
}
}
</script>
*/
}
我怎么做这样的事情?我想,当用户preSS是返回true,我知道他pressed是...我可以这样做?
how can i do such a thing? i want when user press yes return true and i know he pressed yes...can i do so?
推荐答案
如果你想为添加从asp.net的JavaScript到您的网页,你可以使用 ClientScript
类。
If you're trying to add JavaScript to your page from asp.net, you can use the ClientScript
class.
string script = "function update() { var result = confirm(\"Do you want to delimit the record?\") if (result) {return true; } else { return false; } }";
ClientScript.RegisterClientScriptBlock(this.GetType(), "someKey", script, false);
如果你想为呼叫(客户端)JavaScript函数从asp.net code的背后,则绝对不行。当页的帖子,你的C#运行,这是页面上的任何JavaScript不再存在。
If you're trying to call (client side) JavaScript functions from your asp.net code behind, then absolutely not. When the page posts and your C# is run, any JavaScript that was on the page no longer exists.
这篇关于如何调用asp.net web应用程序的JavaScript方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!