PDA

View Full Version : [CLOSED] After hiding popup window



cwolcott
May 01, 2012, 9:35 PM
After I hide/close a popup window is the an easy way to notify the associated parent to perform an action?

After hiding the popup window I want to tell the grid to refresh itself because I have deleted some rows. I have an associated thread (http://forums.ext.net/showthread.php?18720-Window-popup) that is asking if I am showing the popup properly.

I the code behind for the popup I execute the following to hide the popup:



X.AddScript("parentAutoLoadControl.hide()");

Aurelio
May 01, 2012, 9:57 PM
Hi.. i use the new fantastic component MessageBus to notify action to other component and work great...It could be for you..

This is a small sample from send e receive event from the messagebus


<%@ Page Language="C#" %>
<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<!DOCTYPE html>
<html>
<head id="Head1" runat="server">
<title></title>
</head>
<body>
<form id="Form1" runat="server">
<ext:ResourceManager ID="ResourceManager1" runat="server" />
<ext:Window ID="Window1" runat="server" Collapsible="true" Height="185" Icon="Application"
Title="Window1" Width="350" X="10" Y="10">
<Items>
<ext:TextField ID="TextField2" runat="server" Text="Test">
</ext:TextField>
<ext:Button ID="Button1" runat="server" Text="Send value of field to window2">
<Listeners>
<%-- //Send to messagebus an event with name refresh--%>
<Click Handler="Ext.net.Bus.publish('refresh', #{TextField2}.getValue());" />
</Listeners>
</ext:Button>
</Items>

</ext:Window>
<ext:Window ID="Window2" runat="server" Collapsible="true" Height="185" Icon="Application"
Title="Window2" Width="350" Y="220" X="10">
<Items>
<ext:TextField ID="TextField1" runat="server">
</ext:TextField>
</Items>
<%-- //It listens from the messagebus and takes all the events named refresh--%>
<MessageBusListeners>
<ext:MessageBusListener
Name="refresh"
Handler="#{TextField1}.setValue(data);"
/>
</MessageBusListeners>
</ext:Window>

</form>
</body>
</html>

Thanks
Aurelio

Daniil
May 02, 2012, 11:12 AM
Hi all,

Yes, I think Aurelio is right - MessageBus looks to be the best to achieve your requirement.

There are some online examples as well.
http://examples2.ext.net/#/MessageBus/Basic/Simple/
http://examples2.ext.net/#/MessageBus/Basic/Complex/

MessageBus can work with iframes as well.
http://forums.ext.net/showthread.php?17962&p=78276&viewfull=1#post78276

cwolcott
May 02, 2012, 5:10 PM
Sounds perfect. Within the code behind SubmitButton_Click I execute the following:



X.AddScript("parentAutoLoadControl.hide()");
MessageBus.Default.Publish("refresh", "Please refresh the grid");


I have not added a listener anywhere yet, because the code is hanging on the call to MessageBus.Default.Publish. Am I missing something?

Aurelio
May 02, 2012, 7:19 PM
Hi, the comand:
MessageBus.Default.Publish("refresh", "Please refresh the grid");

is Ok, you have Publish on a messageBus the message called "Refresh" with the parameter: "Please refresh the grid" in this case is a String parameter.

In the grid you must refresh, insert the comand:


<MessageBusListeners>
<ext:MessageBusListener
Name="refresh"
Handler="Call a method to refresh the grid;" //data = parameter, in this case you send a string "Please refresh the grid"
/>
</MessageBusListeners>


This comand receved only the message called "refresh", publish on the button, if another component send a message on a messagebus called "refresh" obviously the message is intercepted by the grid, i use name unique for the message in this way the message is intercepted only by the affected component.
I hope it was helpful, sorry for my bad English.

Thanks
Aurelio

cwolcott
May 02, 2012, 9:30 PM
For testing purposes does there have to be a receiving listener? I added the publish in my behind code but the window is no longer hiding. If I take out the MessageBus.Default.Publish it hides. Any thoughts?



protected void SubmitButton_Click(object sender, DirectEventArgs e)
{
// Do something since the submit button was pressed;

// Hide the window and publish a message on the bus.
X.AddScript("parentAutoLoadControl.hide()");
MessageBus.Default.Publish("refresh", "Please refresh the grid");
}

Daniil
May 02, 2012, 9:35 PM
Yes, Aurelio is right. You should listen a MessageBus event that you publish.

Example Parent Page

<%@ Page Language="C#" %>

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>

<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
if (!X.IsAjaxRequest)
{
Store store = this.GridPanel1.GetStore();
store.DataSource = new object[]
{
new object[] { "test1" },
new object[] { "test2" },
new object[] { "test3" }
};
store.DataBind();
}
}
</script>

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

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Ext.NET v2 Example</title>
</head>
<body>
<form runat="server">
<ext:ResourceManager runat="server" />

<ext:Window ID="Window1" runat="server" Hidden="true">
<Loader runat="server" Mode="Frame" Url="Test.aspx">
<LoadMask ShowMask="true" />
</Loader>
</ext:Window>

<ext:GridPanel ID="GridPanel1" runat="server" AutoHeight="true">
<Store>
<ext:Store runat="server">
<Model>
<ext:Model runat="server">
<Fields>
<ext:ModelField Name="test" />
</Fields>
</ext:Model>
</Model>
</ext:Store>
</Store>
<ColumnModel runat="server">
<Columns>
<ext:Column runat="server" Text="Test" DataIndex="test" Width="200">
<Renderer Handler="return value + ' _ ' + Ext.Date.now();" />
</ext:Column>
</Columns>
</ColumnModel>
<MessageBusListeners>
<ext:MessageBusListener Name="refresh" Handler="alert(data); this.getView().refresh();" />
</MessageBusListeners>
</ext:GridPanel>

<ext:Button runat="server" Text="Open Window with iframe">
<Listeners>
<Click Handler="App.Window1.show();" />
</Listeners>
</ext:Button>
</form>
</body>
</html>

Example Child Page

<%@ Page Language="C#" %>

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>

<script runat="server">
protected void Close(object sender, DirectEventArgs e)
{
X.Js.AddScript("parentAutoLoadControl.hide();");
MessageBus.Default.Publish("refresh", "Click OK to refresh the grid.");
}
</script>

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

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Ext.NET v2 Example</title>
</head>
<body>
<ext:ResourceManager runat="server" />
<ext:Button runat="server" Text="Close the Window" OnDirectClick="Close" />
</body>
</html>

cwolcott
May 03, 2012, 1:56 PM
Thank you very much for the example. Once I changed the code to hide the popup from:


X.AddScript("parentAutoLoadControl.hide()");
to

X.Js.AddScript("parentAutoLoadControl.hide();");

everything worked.

Please close the thread.

Daniil
May 03, 2012, 2:50 PM
X.AddScript("parentAutoLoadControl.hide()");


I think it should work as well if you would add semicolon at the end.

X.AddScript("parentAutoLoadControl.hide();");

cwolcott
May 03, 2012, 3:08 PM
Argh, damn semicolons.
My eyes are failing me. It does work.

Please close thread.

Daniil
May 03, 2012, 3:13 PM
Yes, we don't add them automatically, because the developer can do something like this.

X.AddScript("parentAutoLoadControl");
X.AddScript(".");
X.AddScript(".hide();");