开发者

ASP.NET one-to-one chat application

开发者 https://www.devze.com 2023-03-25 03:34 出处:网络
I have developed a simple ASP.NET Ajax chat appliaction.I want to upgrade it.In my project I have an online user list and I am clicking one of them to open a n开发者_C百科ew web browser window (I am d

I have developed a simple ASP.NET Ajax chat appliaction.I want to upgrade it.In my project I have an online user list and I am clicking one of them to open a n开发者_C百科ew web browser window (I am doing this with javascript window.open() ). Now I want to improve my project.

I want to open a dynamic div instead of a new window. This can be a jquery chat box as well. So my question is:

How i will open that div or jquery box and how I will import my asp.net controls (update panel, timer etc.) into to that dynamic div ??


You can do this with the dynamic loader plugin (You'll find full sample there) First use ajax to call the user control:

$(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;
        });
    });

Define a service (svc) that serves the control so your jquery can make calls to them:

    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]
    }
}


The Best way to create is to create a dnymic tabular structure when you click on the link of the online user . This can be done using javascript and jquery ..and on window.load()

you can refer the below link it shows the chat window like facebook and gmail

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号