[英]How to pass a value from WinForm (C#) to an altogether separate Javascript client chat application
I have a chat application in which I have a client side(javascript) and server-side which is WinForms. 我有一个聊天应用程序,其中有一个客户端(javascript)和服务器端,即WinForms。 I want to pass a value from my FrmConsole.cs file to my converse.js file.
我想将值从FrmConsole.cs文件传递到converse.js文件。 Is there any way I can achieve this?
有什么办法可以实现? I am using XMPP protocol for connecting the client and operator console and I have my own ejabberd server running for the same.
我正在使用XMPP协议连接客户端和操作员控制台,并且我有自己的ejabberd服务器正在运行。 For Example I want to pass this string from my C# code to my Javascript file:
例如,我想将此字符串从C#代码传递到Javascript文件:
private string GetStringValue()
{
return "A string value";
}
And this would be my javascript side code: 这是我的JavaScript辅助代码:
<script language="javascript" type="text/javascript">
var stringValue = '<%=GetStringValue();%>';
alert(stringValue);
</script>
I tried this but its not throwing the expected alert. 我尝试了此操作,但未引发预期的警报。 In the alert it shows
在警报中显示
<%=GetStringValue();%>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript">
function showstring(){
var stringValue = '<%=GetStringValue();%>';
alert(stringValue);
</script>
main body: 主体:
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Javascript", "javascript:showstring();", true);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.