PDA

View Full Version : [CLOSED] MessageBusListener Single



vgvallee
Feb 14, 2013, 9:22 PM
Using the following
<ext:MessageBusListener Name="message" Handler="alert('message');" Single="true"/> results in the handler never firing whereas a value of false will fire multiple times.

I was under the impression that this option was to answer only once to this message. Can anyone point me in the right direction?

Thanks.

Vladimir
Feb 14, 2013, 10:34 PM
Please provide runable test sample reproduces the issue

vgvallee
Feb 15, 2013, 7:56 PM
In constructing my test case, I couldn't replicate the problem entirely: it now fires the event once if Single="true" but it still is fired multiple times if Single="false". Here's what I have:

WebForm1.aspx


<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WIS.WebForm1" Trace="true" %>

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<%@ Register Src="~/WebUserControl1.ascx" TagName="WebUserControl1" TagPrefix="test" %>

<script runat="server">
protected void ServerBusEvent(object sender, DirectEventArgs e)
{
this.Panel2.Body.CreateChild(new DomObject
{
Html = "received message from usercontrol",
Tag = HtmlTextWriterTag.P,
CustomConfig =
{
new ConfigItem("style", "color:green;", ParameterMode.Value)
}
});
}
</script>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
<head id="Head1" runat="server">
<title>MessageBus - Ext.NET Examples</title>
<script type="text/javascript" src="./wis.js"></script>
</head>
<body>
<form id="Form2" runat="server">
<ext:ResourceManager ID="ResourceManager1" runat="server" />

<test:WebUserControl1 ID="WebUserControl1" runat="server" />

<ext:Container ID="Container1" runat="server" Layout="HBoxLayout">
<Items>

<ext:Panel
ID="Panel2"
runat="server"
Title="Category Events"
Width="350"
Height="300"
BodyPadding="5"
Margins="5">
<MessageBusDirectEvents>
<ext:MessageBusDirectEvent Name="Msg.Server" OnEvent="ServerBusEvent" Single="false" />
</MessageBusDirectEvents>
</ext:Panel>
</Items>
</ext:Container>
</form>
</body>
</html>


WebUserControl1.ascx


<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="WebUserControl1.ascx.cs" Inherits="WIS.WebUserControl1" %>

<%@ Register assembly="Ext.Net" namespace="Ext.Net" tagprefix="ext" %>


<ext:Button runat="server" Text="text" />


WebUserControl1.ascx.cs


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WIS
{
public partial class WebUserControl1 : System.Web.UI.UserControl
{
public WebUserControl1()
{
this.Init += new EventHandler(WebUserControl1_Init);
}

public void WebUserControl1_Init(object sender, EventArgs e)
{
Ext.Net.MessageBus.Default.Publish("Msg.Server");
}

protected void Page_Load(object sender, EventArgs e)
{
Ext.Net.X.Js.Call("console.log", "WebUserControl1.Page_Load");
}
}
}

Daniil
Feb 17, 2013, 5:00 AM
Hi @vgvallee,

A DirectEvent request causes executing of page life cycle.

You can use the !X.IsAjaxRequest condition this way.

Example

public void Page_Init(object sender, EventArgs e)
{
if (!X.IsAjaxRequest)
{
Ext.Net.MessageBus.Default.Publish("Msg.Server");
}
}

protected void Page_Load(object sender, EventArgs e)
{
if (!X.IsAjaxRequest)
{
Ext.Net.X.Js.Call("console.log", "WebUserControl1.Page_Load");
}
}

vgvallee
Feb 19, 2013, 10:39 PM
Thanks Daniil, that did it.