Note that there are some explanatory texts on larger screens.

plurals
  1. POASP.NET Updating a UpdatePanel on another client
    primarykey
    data
    text
    <p>Okay. So basically i am working on a message system on a webpage. Users on my webpage is able to send each other messages, but now i want the messages to "pop up" on the receivers screen when sent. Exactly like when somebody on facebook sends you a message while your online, the message thing goes red. To solve my problem i need every client to know which other clients are online at the moment. I have solved this by coding an Observer-like pattern in my Global.asax:</p> <pre><code> public static void AddObserver(Observer o) { if(!observers.Contains(o)) observers.Add(o); System.Diagnostics.Debug.WriteLine("Observer tilføjet : " + observers.Count); } public static void RemoveObserver(Observer o) { if (observers.Contains(o)) observers.Remove(o); System.Diagnostics.Debug.WriteLine("Observer fjernet : " + observers.Count); } public static void NotifyObserversNewMail(Observer observer) { foreach (Observer o in observers) if(!o.Equals(observer)) o.UpdateNewMail(); } </code></pre> <p>And the observer in this case i simply the Site.Master, which i have made extend the Observer class :</p> <pre><code>public partial class SiteMaster : System.Web.UI.MasterPage, Observer { protected void Page_Unload(object sender, EventArgs e) { Session["observer"] = this; Global.AddObserver(this); } protected void Page_Load(object sender, EventArgs e) { //ADD OBSERVER TO GLOBAL.ASAX if (Session["observer"] != null) Global.RemoveObserver((Observer)Session["observer"]); public void Update() { DLMessages.DataSource = ServiceMessages.GetInstance().GetMessages(); DLMessages.DataBind(); UPMessages.Update(); } </code></pre> <p>Where DLMessages is a DataList inside the UpdatePanel UPMessages.</p> <p>So we have a "sender" client, and a "receiver" client. When the sender creates a new message this method gets called:</p> <pre><code> protected void MessageSend(object source, EventArgs args) { Page.Validate("ValGroupMessageTo"); if (Page.IsValid) { ServiceMessages.GetInstance().SendMessage(ServiceCommunity.GetInstance().GetUser(MessageTo.Text).Id, ((User)Session["user"]).Id, MessageMessage.Text); Global.NotifyObserversNewMail((Observer)Session["observer"]); ClosePopups(new object(), new EventArgs()); Update(); } } </code></pre> <p>As you can might notice it calls the Notify on global.asax, and the update() directly on itself. The UpdatePanel on the "sender" side updates perfectly, but on the receiver side nothing happens. Not in the UpdatePanel anyways. Cause if i alter the code in the Update() to run through the messages from the DB, i can see that the message gets called fine, and the new message is loaded. Just not updated to the UpdatePanel. So i have been thinking a lot about why the updatepanel doesnt get updated on the "receiver" side when the data gets updated, and my conclusion is it is because theres no partial postback on the "receiver" side. Yeah sure, the Update() method gets called, but theres no postback. So my question is this: Is it possible to "force" a partial post back from the code-behind? Or is there another solution that might work better?</p> <p>Hope it makes sense :-)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload