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

  1. #1

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

    Hi... I´m 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. I´m 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>
    Last edited by Daniil; Mar 16, 2012 at 11:44 AM. Reason: [CLOSED]
  2. #2
    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
  3. #3
    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)?
  4. #4
    Quote Originally Posted by supera View Post
    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/#!...xt.util.KeyMap

    Quote Originally Posted by supera View Post
    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/#!...thod-fireEvent

    Or just call a respective function defined within the IFrame.
  5. #5
    Hi Daniil

    Works very fine!

    Thanks a lot! I´m very pleased with your help!

Similar Threads

  1. Replies: 0
    Last Post: Aug 01, 2012, 1:20 AM
  2. Replies: 3
    Last Post: Mar 26, 2012, 1:43 PM
  3. Replies: 2
    Last Post: Mar 16, 2012, 7:09 PM
  4. [CLOSED] Ext.net v2 Beta release: Top align don´t works
    By supera in forum 2.x Legacy Premium Help
    Replies: 2
    Last Post: Mar 16, 2012, 5:53 PM
  5. [CLOSED] Css Styles to Disabled controls don´t works in IE 9
    By supera in forum 2.x Legacy Premium Help
    Replies: 4
    Last Post: Mar 07, 2012, 10:09 AM

Posting Permissions