Elad Lachmi
Elad Lachmi

Reputation: 10561

asp.net - user notification implementation

I am adding an stackoverflow-esq type of notification bar to my site. On the server side I am adding divs for display:

for (int i = 0; i < dt.Rows.Count; i++ )
        {
            string script = "<div class='hover-notification' style='display:none;'>";
            script += dt.Rows[i]["messageText"].ToString();
            if ((bool)dt.Rows[i]["canDismiss"] == false)
                script += "<span class='dismiss'><a title='Dismiss notification'>x</a></span>";
            script += "</div>";
            ClientScript.RegisterClientScriptBlock(this.GetType(), "clientScript" + i, script);

        }

The client side code is:

$(document).ready(function () {
        $('.hover-notification').prependTo('body').slideDown('slow');
        $('.dismiss').click(function () { $(this).parent().slideUp('slow').remove(); });
    });

I have a table which holds all of the messages for all users and has a messageID primary key. Messages are added to the table on some events, and messages which are not dismiss-able are removed in other events. What I want to do is mark the message as dismissed once the user clicks the dismiss button.

I'm not sure how to do this. Could someone please point me in the right direction?

p.s. I'm also open to any comments on the server-side/client-side code I have so far.

Upvotes: 1

Views: 648

Answers (2)

S P
S P

Reputation: 4643

Add WCF Rest-service to your project and define an operation contract that looks like this:

(Pseudo)

 [OperationContract]
 [WebGet(UriTemplate = "MyService/DismissMessage({x})")]
 public bool DismissMessage(int id) {
    var success = MyLibrary.DismissMessage(id);
    return success; 
 }

In jQuery, simply call your WCF-service as follows:

$.getJSON('MyService/DismissMessage('+messageId+')', function(data) {
   // do something on success or fail
}

For further reading, I suggest you to check this article: http://www.codeproject.com/KB/ajax/jQueryWCFRest.aspx

Upvotes: 1

ChristopheCVB
ChristopheCVB

Reputation: 7315

If I understand your needs, you want to approve dismiss on server side.

Try :

$('.dismiss').click(function () {
    $(this).parent().slideUp('slow').remove();
    // ajax request to server
    $.get('dismiss.asp?id='+this.id);
});

What you have to do is create this dismiss.asp receiving an id freshly pushed on the :

<a id='123' class='dismiss'>x</a>

Am I responding to your question ?

Upvotes: 1

Related Questions