Pregunta

Tengo un problema cuando se manipula el caso de un ReceiveCompleted MessageQueue en ASP.NET. Es lo atrapa con éxito, pero cada cambio aplicado a los controles de la página no tienen ningún efecto.

Esto es lo que tengo:

.ASPX

<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="False">
   <ContentTemplate>
       <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
       <br />
       <asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
   </ContentTemplate>
</asp:UpdatePanel>

<asp:Timer ID="Timer1" runat="server" Interval="3000" ontick="Timer1_Tick">
</asp:Timer>

.CS

private static System.Messaging.MessageQueue queue;
private static String messageContent;

protected override void OnInit(EventArgs e)
{
    base.OnInit(e);
    queue = new MessageQueue(@".\Private$\MyQueue");
    queue.ReceiveCompleted += new ReceiveCompletedEventHandler(mq_ReceiveCompleted);
    queue.BeginReceive();
}


protected void mq_ReceiveCompleted(object sender, System.Messaging.ReceiveCompletedEventArgs e)
{

    System.Messaging.Message message = queue.EndReceive(e.AsyncResult);
    message.Formatter = new System.Messaging.XmlMessageFormatter(new string[] { "System.String,mscorlib" });

    Label1.Text = message.Body.ToString();      //Has no effect. The value updates without problem, but doesn't persist after finishing this method. And the Page doesn't refresh with this new value.
    Label2.Text = DateTime.Now.ToString();      //Has no effect too.
    Timer1.Interval = 99999;                    //And this one the same, no effect.
    messageContent = message.Body.ToString();   //.. But the value stored in this variable does persist

    queue.BeginReceive();
}

No por qué no funciona la actualización de los VARS. Puede ser cualquier nonesense, pero soy nuevo en ASP.NET, por lo que cualquier idea será bienvenida.

Gracias de antemano!

Pablo

¿Fue útil?

Solución

Se quiere que la página del cliente a ser actualizada por el comando (causada por mq_ReceiveCompleted) desde el servidor, ¿verdad? No es posible, si así es.

Mi sugerencia es poner una función JS cliente que será llamado por el contador de tiempo (cada segundo o así) y le enviará una solicitud asíncrona AJAX para el servicio web para los nuevos mensajes en MessageQueue. Si existe dicho mensaje de la JS tomará las acciones necesarias (la actualización de la página, etc.)

Otros consejos

Trate de establecer el UpdateMode = "siempre" para su UpdatePanel, o UpdatePanel1.Update(); llamada al final de Método mq_ReceiveCompleted ().

Compruebe que está actualizando la instancia correcta del objeto de página.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top