SignalIR and KnockoutJS in Asp.Net Web Form(Asp.Net Web 表单中的 SignalIR 和 KnockoutJS)
问题描述
我在 MVC 平台上看到了 SignalIR 和 KnockoutJS 示例,但在 WebForm 上没有.请建议我,我们可以在 WebForm 上使用吗?任何文章链接将是可观的.
我知道这正好晚了一个月,但这里有一个简单的例子 [这是我通过探索MVC 示例]
假设您有一个名为 MyPage 的页面
在 .aspx 文件中写入以下内容:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="MyPage.aspx.cs" Inherits="MyPage" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head runat="服务器"><title></title><script src="U2NyaXB0cy9qcXVlcnktMS42LjQubWluLmpz" type="text/javascript"></script><script src="U2NyaXB0cy9qcXVlcnkuc2lnbmFsUi0wLjUuMi5taW4uanM=" type="text/javascript"></script><script type="text/javascript" src="Jmx0OyU9IFJlc29sdmVDbGllbnRVcmwo"~/signalr/hubs") %>'></script><script type="text/javascript">$(函数(){var conChat = $.connection.chat;conChat.addMessage = 函数(消息){$('#disMess').append('' + message + ' ');};$("#btnSend").click(function () {conChat.send($('#txtMess').val());$('#txtMess').val('');});$.connection.hub.start();});头部><身体><form id="form1" runat="server"><div><ul id="disMess"></ul><input id="txtMess"/><!-- 参见 onclick 也--><input id="btnSend" type="button" value="Send"/>
</表单>
实际上 .cs 文件 [或背后的代码] 中没有任何内容
您需要添加 ASP.NET 文件夹Add_Code"并使用以下代码在其中放置一个类Chat.cs":
使用系统;使用 System.Collections.Generic;使用 System.Linq;使用 System.Web;使用 SignalR.Hubs;命名空间 NewSignalRChat{公开课聊天:中心{公共无效发送(字符串味精){Clients.addMessage(msg);}}}
I seen may samples of SignalIR and KnockoutJS samples on MVC platform but not on WebForm. Please suggest me, can we use on WebForm? Any articles link would be appreciable.
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 MVC examples]
lets say u have a page called MyPage
in the .aspx file write the following:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="MyPage.aspx.cs" Inherits="MyPage" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="U2NyaXB0cy9qcXVlcnktMS42LjQubWluLmpz" type="text/javascript"></script>
<script src="U2NyaXB0cy9qcXVlcnkuc2lnbmFsUi0wLjUuMi5taW4uanM=" type="text/javascript"></script>
<script type="text/javascript" src="Jmx0OyU9IFJlc29sdmVDbGllbnRVcmwo"~/signalr/hubs") %>'></script>
<script type="text/javascript">
$(function () {
var conChat = $.connection.chat;
conChat.addMessage = function (message) {
$('#disMess').append('<li>' + message + '</li>');
};
$("#btnSend").click(function () {
conChat.send($('#txtMess').val());
$('#txtMess').val('');
});
$.connection.hub.start();
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<ul id="disMess"></ul>
<input id="txtMess" />
<!-- see onclick also -->
<input id="btnSend" type="button" value="Send" />
</div>
</form>
</body>
</html>
and actually nothing in the .cs file [or the code behind]
you'll need to add the ASP.NET folder "Add_Code" and place a class "Chat.cs" in it with the following 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);
}
}
}
这篇关于Asp.Net Web 表单中的 SignalIR 和 KnockoutJS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Asp.Net Web 表单中的 SignalIR 和 KnockoutJS


- 在 C# 中异步处理项目队列 2022-01-01
- CanBeNull和ReSharper-将其用于异步任务? 2022-01-01
- 带问号的 nvarchar 列结果 2022-01-01
- C# 通过连接字符串检索正确的 DbConnection 对象 2022-01-01
- Azure Active Directory 与 MVC,客户端和资源标识同一 2022-01-01
- Windows 喜欢在 LINUX 中使用 MONO 进行服务开发? 2022-01-01
- 在 LINQ to SQL 中使用 contains() 2022-01-01
- 使用 rss + c# 2022-01-01
- 是否可以在 .Net 3.5 中进行通用控件? 2022-01-01
- 为什么 C# 中的堆栈大小正好是 1 MB? 2022-01-01