简体   繁体   中英

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. I want to pass a value from my FrmConsole.cs file to my converse.js file. 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. For Example I want to pass this string from my C# code to my Javascript file:

private string GetStringValue()
{
  return "A string value";
}

And this would be my javascript side code:

<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); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM