[英]Div doesn't update in asp.net SignalR
I'm working with SignalR
and I don't want to use JavaScript
to connect to the hub.我正在使用
SignalR
,但不想使用JavaScript
连接到集线器。
This is the part of my codes:这是我的代码的一部分:
index.aspx:索引.aspx:
<form id="form1" runat="server">
<asp:ScriptManager ID="scriptManager" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="updatePanel" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<div>
<div runat="server" id="DivMessage" style="width:100%; height: 250px;"></div>
<asp:TextBox runat="server" ID="TextBoxName"></asp:TextBox>
<asp:Button runat="server" ID="ButtonLogin" Text="LOGIN" OnClick="ButtonLogin_Click"/>
<asp:Button runat="server" ID="ButtonMessage" Text="SEND" OnClick="ButtonMessage_Click"/>
</div>
</ContentTemplate>
</asp:UpdatePanel>
</form>
index.aspx.cs: index.aspx.cs:
namespace ASPNetSignalR
{
public partial class index : System.Web.UI.Page
{
private static string uri = "http://localhost:4933";
private static HubConnection connection;
private static IHubProxy proxy;
...
}
protected void ButtonLogin_Click(object sender, EventArgs e)
{
RunSignalRClient();
}
protected void ButtonMessage_Click(object sender, EventArgs e)
{
SendMessage("Ehsan: Hello!");
}
public void RunSignalRClient()
{
connection = new HubConnection(uri);
proxy = connection.CreateHubProxy("ASPNetSignalRHub");
connection.Start().Wait();
proxy.On<string>("SendMessage", SendMessage =>
{
DivMessage.InnerHtml += "<p>" + SendMessage + "</p>";
});
}
public void SendMessage(string message)
{
proxy.Invoke<string>("SendMessage", new object[] { message });
}
}
Startup.cs:启动.cs:
using Microsoft.Owin;
using Owin;
[assembly: OwinStartup(typeof(ASPNetSignalR.Startup))]
namespace ASPNetSignalR
{
public class Startup
{
public void Configuration(IAppBuilder app)
{
app.MapSignalR();
}
}
}
When I run this, everything works correctly and DivMessage.InnerHtml += "<p>" + SendMessage + "</p>";
当我运行它时,一切正常并且
DivMessage.InnerHtml += "<p>" + SendMessage + "</p>";
runs (like the following image), but nothing shows in the web page.运行(如下图所示),但网页中没有显示任何内容。
Where I wrong?我哪里错了?
Thanks谢谢
尝试以下操作:
$("#DivMessage").append(SendMessage);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.