如何在C#代码中调用javescript [英] How to call javescript in C# code

查看:87
本文介绍了如何在C#代码中调用javescript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

美好的一天,



如何从C#调用java脚本?我尝试了Response.Write()和Page.ClientScript ......但我仍然无法使它工作。 javascript是一个弹出消息框



< script>

$ .msg({

bgPath:'../Pictures/Images/',

内容:'

服务器错误

',

klass:'white',

fadeIn:'200',

fadeOut:'100',

timeOut:'10000'

});

< / script>





我想在C#按钮点击事件中调用它



谢谢

解决方案

.msg({

bgPath:'../Pictures/Images/',

content:'

Server Error

',

klass:'white',

fadeIn:'200',

fadeOut:'100',

timeOut:'10000'

});

< / script>





我想要o在C#按钮点击事件中调用它



谢谢


我建​​议你把这个代码放在一个javascript函数中,比如这个:



 < script  >  

函数myFunction(){


.msg({
bgPath:' ../ Pictures / Images /'
content:'
服务器错误

'

klass:' white'
fadeIn:' 200'
fadeOut:' 100'
timeOut:' 10000'
});

}
< / script >





在c#中调用此函数,如下所示:



  //  如果您没有使用ScriptManager你的页面是这样的: 

ClientScript.RegisterStartupScript(GetType(), js myFunction(););

// 如果你的页面上有ScriptManager,那么就像这样:

ScriptManager.RegisterStartupScript(Page,Page.GetType(), js myFunction(); true );


Good day,

How can I call java script from C#? I tried Response.Write() and Page.ClientScript... but still I can't make it work. The javascript is a pop up messagebox

<script>
$.msg({
bgPath: '../Pictures/Images/',
content: '

Server Error

',
klass: 'white',
fadeIn: '200',
fadeOut: '100',
timeOut: '10000'
});
</script>


I want to call this in C# button click event

Thank you

解决方案

.msg({
bgPath: '../Pictures/Images/',
content: '

Server Error

',
klass: 'white',
fadeIn: '200',
fadeOut: '100',
timeOut: '10000'
});
</script>


I want to call this in C# button click event

Thank you


I Suggest U to put this code in a javascript function, like this :

<script>

function myFunction() {


.msg({ bgPath: '../Pictures/Images/', content: ' Server Error ', klass: 'white', fadeIn: '200', fadeOut: '100', timeOut: '10000' }); } </script>



call this function in c# like this :

// if u don't have ScriptManager on your page then like this :

ClientScript.RegisterStartupScript(GetType(), "js", "myFunction();", true);

// if u have ScriptManager on your page then like this :

ScriptManager.RegisterStartupScript(Page, Page.GetType(), "js", "myFunction();", true);


这篇关于如何在C#代码中调用javescript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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