ASP.. NET一对一聊天应用程序

ASP.NET one-to-one chat application

本文关键字:应用程序 聊天 一对一 NET ASP      更新时间:2023-09-26

我已经开发了一个简单的ASP。. NET Ajax聊天应用程序。我想升级一下。在我的项目中,我有一个在线用户列表,我正在单击其中一个打开一个新的web浏览器窗口(我正在使用javascript窗口。open())。现在我想改进我的项目。

我想打开一个动态div而不是一个新窗口。这也可以是一个jquery聊天框。所以我的问题是:

我将如何打开那个div或jquery框,我将如何导入我的asp.net控件(更新面板,定时器等)到那个动态div ??

您可以使用动态加载器插件(您可以在那里找到完整的示例)首先使用ajax调用用户控件:

$(function() {
        var content = $('#content');
        var btnAddCell = $('#btn-add-table');
        var tableid = 1
        //dynamically add a new table to the page when the add button is clicked
        btnAddCell.click(function() {
            $.dynamicLoader.loadUC({
                ucName: 'UserControls/TableWidget.ascx',
                queryString: 'tableid=' + tableid++,
                eventBindings: {
                    ready: function(wrappedData) {
                        content.append(wrappedData);
                    } //here is where we get the rendered html and attach to the row
                }
            });
            return false;
        });
    });

定义一个服务(svc)来提供控件,这样你的jquery就可以调用它们了:

    namespace DynamicLoader
{
    [ServiceContract(Namespace = "")]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class Ajax
    {
        // Add [WebGet] attribute to use HTTP GET
        [WebGet]
        [OperationContract]
        public Stream RenderUC(string path)
        {
            Page pageHolder = new Page();
            UserControl viewControl = (UserControl)pageHolder.LoadControl(path);
            pageHolder.Controls.Add(viewControl);
            StringWriter output = new StringWriter();
            HttpContext.Current.Server.Execute(pageHolder, output, true);
            //trick to output exactly what you want (without wcf wrapping it)
            return new MemoryStream(Encoding.UTF8.GetBytes(output.ToString()));
        }
        // Add more operations here and mark them with [OperationContract]
    }
}

最好的创建方式是在点击在线用户的链接时创建一个动态表格结构。这可以使用javascript和jquery完成。on window。load()

你可以参考下面的链接它显示了像facebook和gmail这样的聊天窗口

http://20fingers2brains.blogspot.com/2013/03/gmail-facebook-style-online-chat.html