PDA

View Full Version : [CLOSED] Window created in Code Behind: default Button don´t works



supera
Mar 15, 2012, 6:54 PM
Hi... Im creating then window in codebehind. Buttons too.
I set in button.listner.click.handler the code to be executed when the button is clicked, as follow.



successHandler = String.Format("function (result) {{ if (result) {{ Ext.defer({0}.close, 1, {0}); }}}}", wnd.ClientID)
btn.Listeners.Click.Handler = String.Format("{0}.getBody().{1}({{ success : {2} }});", wnd.ClientID, "Ext.net.DirectMethods.IsVerified", successHandler)


If I click in button, works fine... but when I press key [ENTER], the button Ok is not fired. Im set de DefaultButton property of window as follow:



wnd.DefaultButton = "button[text=Ok]"


I think that the listner (click) that I use is incorrect! There are another listner that I can use?

Follow the sample project:

Main page



<%@ 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 = "~/test30.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" & (New System.Random).Next(Integer.MaxValue).ToString
btn.Text = "Ok"
btn.TextAlign = ButtonTextAlign.Center
btn.Icon = Icon.Accept

successHandler = String.Format("function (result) {{ if (result) {{ Ext.defer({0}.close, 1, {0}); }}}}", wnd.ClientID)
btn.Listeners.Click.Handler = String.Format("{0}.getBody().{1}({{ success : {2} }});", wnd.ClientID, "Ext.net.DirectMethods.IsVerified", successHandler)

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

btn = New Ext.Net.Button
btn.ID = "btnCancel" & (New System.Random).Next(Integer.MaxValue).ToString
btn.Text = "Cancel"
btn.TextAlign = ButtonTextAlign.Center
btn.Icon = Icon.Cancel
btn.Listeners.Click.Handler = wnd.ClientID & ".close();"
wnd.Buttons.Add(btn)

wnd.DefaultButton = "button[text=Ok]"

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 id="Head1" 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">
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
txtDescription.Focus(True, 50)
End Sub

<DirectMethod()>
Public Function IsVerified() As Boolean
Return True
End Function

</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
</head>
<body>
<ext:ResourceManager ID="resManagerSGCO" runat="server" />
<form id="form1" runat="server">
<ext:TextField runat="server" ID="txtDescription" FieldLabel="Description" Text = "" />
</form>
</body>
</html>

Vladimir
Mar 15, 2012, 7:09 PM
Iframe doesn't buuble events to parent page therefore in your case (when a window uses Loader with Frame mode) you cannot use DefaultButton functionality

supera
Mar 15, 2012, 7:59 PM
Any suggestion how I can work around this?

Can I intercept the [ENTER] key in my aspx pages and simulate a click in button Ok in parent object (in this case, Window)?

Daniil
Mar 15, 2012, 9:38 PM
Can I intercept the [ENTER] key in my aspx pages

Example

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

<%@ 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">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Ext.NET v2 Example</title>
</head>
<body>
<ext:ResourceManager runat="server">
<Listeners>
<DocumentReady Handler="Ext.getBody().focus();" />
</Listeners>
</ext:ResourceManager>

<ext:KeyMap runat="server" Target="={Ext.isGecko ? Ext.getDoc() : Ext.getBody()}">
<ext:KeyBinding>
<Keys>
<ext:Key Code="ENTER" />
</Keys>
<Listeners>
<Event Handler="alert('Enter');" />
</Listeners>
</ext:KeyBinding>
</ext:KeyMap>
</body>
</html>


See also
http://docs.sencha.com/ext-js/4-0/#!/api/Ext.util.KeyMap


simulate a click in button Ok in parent object (in this case, Window)?

You can use the fireEvent method of the Button.
http://docs.sencha.com/ext-js/4-0/#!/api/Ext.util.Observable-method-fireEvent

Or just call a respective function defined within the IFrame.

supera
Mar 16, 2012, 12:40 PM
Hi Daniil

Works very fine!

Thanks a lot! Im very pleased with your help!