Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I know this is exactly a month late but here's a quick example [this is a trivial example that i have built from exploring <a href="http://raselbappi.blogspot.com/2012/03/aspnet-mvc-4-real-time-communication.html" rel="nofollow">MVC examples</a>]</p> <p>lets say u have a page called MyPage</p> <p>in the .aspx file write the following:</p> <pre><code>&lt;%@ Page Language="C#" AutoEventWireup="true" CodeFile="MyPage.aspx.cs" Inherits="MyPage" %&gt; &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head runat="server"&gt; &lt;title&gt;&lt;/title&gt; &lt;script src="Scripts/jquery-1.6.4.min.js" type="text/javascript"&gt;&lt;/script&gt; &lt;script src="Scripts/jquery.signalR-0.5.2.min.js" type="text/javascript"&gt;&lt;/script&gt; &lt;script type="text/javascript" src='&lt;%= ResolveClientUrl("~/signalr/hubs") %&gt;'&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; $(function () { var conChat = $.connection.chat; conChat.addMessage = function (message) { $('#disMess').append('&lt;li&gt;' + message + '&lt;/li&gt;'); }; $("#btnSend").click(function () { conChat.send($('#txtMess').val()); $('#txtMess').val(''); }); $.connection.hub.start(); }); &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;form id="form1" runat="server"&gt; &lt;div&gt; &lt;ul id="disMess"&gt;&lt;/ul&gt; &lt;input id="txtMess" /&gt; &lt;!-- see onclick also --&gt; &lt;input id="btnSend" type="button" value="Send" /&gt; &lt;/div&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>and actually nothing in the .cs file [or the code behind]</p> <p>you'll need to add the ASP.NET folder "Add_Code" and place a class "Chat.cs" in it with the following code:</p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Web; using SignalR.Hubs; namespace NewSignalRChat { public class Chat : Hub { public void Send(string msg) { Clients.addMessage(msg); } } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload