在處理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的新手,所以任何線索都會受到歡迎。
在此先感謝!
巴勃羅
您是否有UpdateManager的ScriptManager? – curtisk 2010-01-29 16:49:58
是的,我喜歡這個: asp:ScriptManager> \t ... ASP:的UpdatePanel> –
Pablo
2010-01-30 15:56:40