PDA

View Full Version : [CLOSED] When directMethod returns True, I wish that window is closed



supera
Mar 13, 2012, 9:35 PM
Hi!

I have two aspx page.
In main page (test26.aspx), I create a window (in codebehind) and I load within this window the test27.aspx page.
In test27.aspx (child page) I have a directmethod called Save, and this functions return true or false.
I wish when the directMethod Save returns true, the window was closed.

the code to call a directMethod is in btnOk of window:


btn.OnClientClick = wnd.ClientID & ".getBody().Ext.net.DirectMethods.Save();"


Any help?



<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Text26.aspx.vb" Inherits="WebApplication3.Text26" %>
<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>

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

<script runat="server">

Protected Sub AddWindow(sender As Object, evt As Ext.Net.DirectEventArgs)
Dim wnd As Ext.Net.Window
wnd = getWindow()
Me.Form.Controls.Add(wnd)
wnd.Render()
wnd.Show()
End Sub

Protected Function getWindow(Optional url As String = "~/test27.aspx", Optional pTitle As String = "test", Optional iconUrl As String = "") As Ext.Net.Window
Dim wnd As New Ext.Net.Window
Dim loader As New Ext.Net.ComponentLoader
Dim btn As Ext.Net.Button

loader.Url = url
loader.Mode = Ext.Net.LoadMode.Frame
loader.LoadMask.ShowMask = True
loader.LoadMask.Msg = "Carregando..."

wnd.ID = "window_" & (New System.Random).Next(Integer.MaxValue).ToString
wnd.Title = pTitle
If iconUrl <> "" Then
Else
wnd.Icon = Ext.Net.Icon.ApplicationForm
End If
wnd.AutoRender = False
wnd.Collapsible = False
wnd.Hidden = True
wnd.AutoRender = False
wnd.Maximizable = False
wnd.Loader = loader
wnd.CloseAction = CloseAction.Destroy
wnd.Width = 500
wnd.Height = 400

btn = New Ext.Net.Button
btn.ID = "btnOk"
btn.Text = "Ok"
btn.TextAlign = ButtonTextAlign.Center
btn.Icon = Icon.Accept
btn.OnClientClick = wnd.ClientID & ".getBody().Ext.net.DirectMethods.Save();"
wnd.Buttons.Add(btn)

btn = New Ext.Net.Button
btn.ID = "btnCancel"
btn.Text = "Cancel"
btn.TextAlign=ButtonTextAlign.Center
btn.Icon = Icon.Cancel
btn.OnClientClick = wnd.ClientID & ".close();"
wnd.Buttons.Add(btn)

Return wnd

End Function

<DirectMethod()>
Public Sub ShowMessage()
Dim mb As New Ext.Net.MessageBox
mb.Alert("Parent alert!", "This messages is triggered in parent!").Show()
End Sub

<DirectMethod()>
Public Sub ShowWindow()
Dim wnd As Ext.Net.Window
wnd = getWindow("~/test25.aspx")
Me.Form.Controls.Add(wnd)
wnd.Render()
wnd.Show()
End Sub

</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<ext:ResourceManager ID="resManagerSGCO" runat="server"/>
<form id="form1" runat="server">
<div>
<ext:Button runat="server" ID="btnCreateWindow" Text="Create and Show Window" OnDirectClick="addWindow" />
</div>
</form>
</body>
</html>




<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Test27.aspx.vb" Inherits="WebApplication3.Test27" %>
<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>

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

<DirectMethod()>
Public Function Save() As Boolean
Response.Write("Save triggered!!!")
Return True
End Function
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<ext:ResourceManager ID="resManagerSGCO" runat="server" />
<form id="form1" runat="server">
<div>

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

Daniil
Mar 14, 2012, 12:25 PM
Hi,

You should set up a respective Success handler.

Dim successHandler As String
successHandler = String.Format("function (result) {{ if (result) {{ {0}.close(); }}}}", wnd.ClientID)
btn.OnClientClick = String.Format("{0}.getBody().{1}({{ success : {2} }});", wnd.ClientID, "Ext.net.DirectMethods.Save", successHandler)

P.S. Please leave only:

<%@ Page Language="vb" %>
in your samples instead of

<%@ Page
Language="vb"
AutoEventWireup="false"
CodeBehind="Text26.aspx.vb"
Inherits="WebApplication3.Text26" %>

We just always need to remove it.

supera
Mar 14, 2012, 12:41 PM
Hi Daniil

Now, I get a error when the window is closed!

In message box is written!
Runtime Error in Microsoft JScript: 'Ext' is undefined

3941



P.S. Please leave only:
<%@ Page Language="vb" %>


Ok! Iīm sorry! I will send my code in this format...

Daniil
Mar 14, 2012, 2:19 PM
I was unable to reproduce the problem using the code from the initial post.

Could you provide a sample?

supera
Mar 14, 2012, 2:29 PM
The errors occurs in same sample project...

I've had other errors that you could not reproduce. I think it is because my version
of DP1...

I would like download a new version of DP1, but you recomended that I stay waiting the DP2.

Daniil
Mar 14, 2012, 2:42 PM
I've tried with DP1 as well - no error on my side.


I would like download a new version of DP1, but you recomended that I stay waiting the DP2.

Well, there is some misunderstanding.

There is no new version of DP1 and we didn't plan it. We planned to release DP2.

But made the Beta release which available for the community also.

For you, as a premium member, I would suggest to update directly from SVN, because we hourly (or even minutely) fix reported bugs.
http://svn.ext.net/premium/branches/2.0/

In other words, the SVN version is already far enough from Beta release.

More official info about the release will be available soon.

supera
Mar 14, 2012, 5:37 PM
Hi Daniil!

SVN version is what I want and this is what I meant with 'new version of DP1'... Excuse me for not expressing myself correctly.
Thanks a lot for indicate the url to SVN. I'm keeping my ext.net updated from this point forward.

Well... I downloaded source codes with SVN, compile and update the dlls from url http://svn.ext.net/premium/branches/2.0/.
After this, the <directmethods> donīt works any more.
Probably, I donīt updating correctly.
There are a guide or help to update and compile source codes of ext.net from SVN?

Daniil
Mar 14, 2012, 5:43 PM
Probably, I donīt updating correctly.
There are a guide or help to update and compile source codes of ext.net from SVN?

I bet you did it correctly.



After this, the <directmethods> donīt works any more.

Please try to replace

Ext.net.DirectMethods
with

App.direct
or set up

DirectMethodNamespace="Ext.net.DirectMethods"
for the ResourceManager.

supera
Mar 14, 2012, 5:57 PM
Replacing App.direct, works fine the DirectMethods

But the error persisted:

Runtime Error in Microsoft JScript: 'Ext' is undefined

I need update the extjs or recompile this?

Daniil
Mar 14, 2012, 6:07 PM
I need update the extjs or recompile this?

No, you should not.

Could you provide the latest code that you are trying with the exactly steps to reproduce the problem?

supera
Mar 14, 2012, 6:12 PM
Hi Daniil!

Of course... follow the sample code!



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

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

<script runat="server">

Protected Sub AddWindow(sender As Object, evt As Ext.Net.DirectEventArgs)
Dim wnd As Ext.Net.Window
wnd = getWindow()
Me.Form.Controls.Add(wnd)
wnd.Render()
wnd.Show()
End Sub

Protected Function getWindow(Optional url As String = "~/test27.aspx", Optional pTitle As String = "test", Optional iconUrl As String = "") As Ext.Net.Window
Dim wnd As New Ext.Net.Window
Dim loader As New Ext.Net.ComponentLoader
Dim btn As Ext.Net.Button
Dim successHandler As String

loader.Url = url
loader.Mode = Ext.Net.LoadMode.Frame
loader.LoadMask.ShowMask = True
loader.LoadMask.Msg = "Carregando..."

wnd.ID = "window_" & (New System.Random).Next(Integer.MaxValue).ToString
wnd.Title = pTitle
If iconUrl <> "" Then
Else
wnd.Icon = Ext.Net.Icon.ApplicationForm
End If
wnd.AutoRender = False
wnd.Collapsible = False
wnd.Hidden = True
wnd.AutoRender = False
wnd.Maximizable = False
wnd.Loader = loader
wnd.CloseAction = CloseAction.Destroy
wnd.Width = 500
wnd.Height = 400

btn = New Ext.Net.Button
btn.ID = "btnOk"
btn.Text = "Ok"
btn.TextAlign = ButtonTextAlign.Center
btn.Icon = Icon.Accept

successHandler = String.Format("function (result) {{ if (result) {{ {0}.close(); }}}}", wnd.ClientID)
btn.OnClientClick = String.Format("{0}.getBody().{1}({{ success : {2} }});", wnd.ClientID, "App.direct.Save", successHandler)

'btn.OnClientClick = wnd.ClientID & ".getBody().Ext.net.DirectMethods.Save();"
wnd.Buttons.Add(btn)

btn = New Ext.Net.Button
btn.ID = "btnCancel"
btn.Text = "Cancel"
btn.TextAlign=ButtonTextAlign.Center
btn.Icon = Icon.Cancel
btn.OnClientClick = wnd.ClientID & ".close();"
wnd.Buttons.Add(btn)

Return wnd

End Function

<DirectMethod()>
Public Sub ShowMessage()
Dim mb As New Ext.Net.MessageBox
mb.Alert("Parent alert!", "This messages is triggered in parent!").Show()
End Sub

<DirectMethod()>
Public Sub ShowWindow()
Dim wnd As Ext.Net.Window
wnd = getWindow("~/test25.aspx")
Me.Form.Controls.Add(wnd)
wnd.Render()
wnd.Show()
End Sub

</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<ext:ResourceManager ID="resManagerSGCO" runat="server"/>
<form id="form1" runat="server">
<div>
<ext:Button runat="server" ID="btnCreateWindow" Text="Create and Show Window" OnDirectClick="addWindow" />
</div>
</form>
</body>
</html>




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

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

<DirectMethod()>
Public Function Save() As Boolean
Response.Write("Save triggered!!!")
Return True
End Function
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<ext:ResourceManager ID="resManagerSGCO" runat="server" />
<form id="form1" runat="server">
<div>

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

Daniil
Mar 14, 2012, 6:24 PM
Thanks. I was able to reproduce with IE. I tried with FireFox where it's not reproducible.

A small delay (1 ms) solves the problem.

Please replace:

successHandler = String.Format("function (result) {{ if (result) {{ {0}.close(); }}}}", wnd.ClientID)
with

successHandler = String.Format("function (result) {{ if (result) {{ Ext.defer({0}.close, 1, {0}); }}}}", wnd.ClientID)

supera
Mar 14, 2012, 8:10 PM
Hi Daniil!

Works fine! Thanks a lot!