2010-01-29 4 views
0

ASP.NET에서 MessageQueue의 ReceiveCompleted 이벤트를 처리 할 때 문제가 있습니다. 성공적으로 캐치하지만 페이지의 컨트롤에 적용된 모든 변경 사항은 적용되지 않습니다.ASP.NET 및 사용자 지정 이벤트 관련 문제

이 내가있어 무엇 :

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

내가 그 바르 업데이트 실패하지 왜. 그것은 무의미 할 수도 있지만 ASP.NET에 익숙하지 않으므로 어떤 단서를 환영 할 것입니다.

미리 감사드립니다.

파블로

+0

updatePanel 용 ScriptManager가 있습니까? – curtisk

+0

그래, 내가 좋아하는 : \t ... Pablo

답변

1

서버에서 mq_ReceiveCompleted 명령에 의해 클라이언트 페이지가 업데이트되기를 원합니다. 그렇다면 불가능합니다.

내 제안은 timer (각 초 정도)에 의해 호출 될 클라이언트 JS 함수를 넣고 MessageQueue의 새 메시지에 대한 비동기식 AJAX 요청을 웹 서비스에 보냅니다. 그러한 메시지가 존재하면 JS는 필요한 조치를 취합니다 (페이지 등 업데이트)

+0

네, 저의 의도였습니다 ... 나는 서빙에서 페이지를 업데이트하는 것이 가능하다고 생각했지만 오해를하고있었습니다. 도움에 감사드립니다! – Pablo

0

의 UpdateMode = "항상"mq_ReceiveCompleted의 끝에서 당신의 UpdatePanel에, 또는 전화 UpdatePanel1.Update();() 방법을 설정하십시오.

+0

감사하지만 성공하지 못했습니다. – Pablo

0

페이지 개체의 올바른 인스턴스를 업데이트하고 있는지 확인하십시오.

+0

어떻게 확인할 수 있습니까? 다음과 같이 말하면됩니다. Label1.Text = m.Body.ToString(); 페이지 자체를 업데이트해야하나요? 어쨌든 GregoryM이 제안한대로 UpdatePanel1.Update()를 추가하려고 시도했지만 작동하지 않습니다. – Pablo

관련 문제