ASP.NET和自定义事件的问题 [英] Problems with ASP.NET and custom events

查看:105
本文介绍了ASP.NET和自定义事件的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在ASP.NET中处理MessageQueue的ReceiveCompleted事件时遇到问题. 它可以成功捕获它,但是应用于页面控件的所有更改均无效.

I have a problem when handling the ReceiveCompleted event of a MessageQueue in ASP.NET. It catches it successfully, but every changes applied to the Controls of the page have no effect.

这就是我所拥有的:

<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的新手,所以欢迎您提供任何线索.

I don't why it fails updating those vars. It may be any nonesense, but I'm new to ASP.NET, so any clue will be welcome.

提前谢谢!

巴勃罗

推荐答案

您希望通过服务器上的命令(由mq_ReceiveCompleted引起)来更新客户端页面,对吗?如果是这样,那是不可能的.

You want the client page to be updated by the command (caused by mq_ReceiveCompleted) from the server, right? It isn't possible if it's so.

我的建议是放置一个客户端JS函数,该函数将由计时器(每秒钟左右)调用一次,并将向Web服务发送异步AJAX请求以在MessageQueue中发送新消息.如果存在此类消息,则JS将采取任何必要的操作(更新页面等)

My suggestion is to put a client JS function that will be called by timer (each second or so) and will send an async AJAX request to the web service for new messages in MessageQueue. If such message exists the JS will take any actions needed (updating the page, etc.)

这篇关于ASP.NET和自定义事件的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆