【问题标题】:ASP.NET one-to-one chat applicationASP.NET 一对一聊天应用程序
【发布时间】:2011-08-03 12:02:43
【问题描述】:

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

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

我将如何打开该 div 或 jquery 框以及如何将我的 asp.net 控件(更新面板、计时器等)导入到该动态 div 中??

【问题讨论】:

    标签: javascript jquery asp.net


    【解决方案1】:

    您可以使用dynamic loader plugin 执行此操作(您会在此处找到完整示例) 先用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]
        }
    }
    

    【讨论】:

      【解决方案2】:

      最好的创建方法是在单击在线用户的链接时创建动态表格结构。 这可以使用 javascript 和 jquery ..和 window.load() 来完成

      您可以参考以下链接 它显示像 facebook 和 gmail 的聊天窗口

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-10-18
        • 2023-03-15
        • 1970-01-01
        • 2017-08-23
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多