Call JavaScript function with an Event in Ext.net

  1. #1

    Call JavaScript function with an Event in Ext.net

    Hellow an thanks for your help. I'm using javascript in my proyect, but now i'm ussing Ext.net but i don't know how i can launch this function with an ext button.

    This is the function:
    function cancel_button(e)
    {
    	graph.newElement = null;
    	graph.newConnection = null;
    
    	graph.track = false;
    	for (var i = 0; i < graph.elements.length; i++) 
    	{
    		var element = graph.elements[i];
    		if (element.tracker !== null) 
    		{
    			element.tracker.track = false;
    		}
    	}
    
    	graph.update();
    	graph.updateActiveObject(graph.pointerPosition);
    	graph.updateMouseCursor();
    	graph.stopEvent(e);
    };
    This is how i use it, from an HTML form:
    <input type="button" id="btnDelete" name="btnDelete" 	title="Borrar [Del]" 			class="button_delete" 	accesskey="-" 	tabindex="5"    onclick="delete_button(event)" />
    I'm tying with Ext.net, but i dont know hoy i can send the "event":
    <ext:Button ID="btnDelete"  runat="server"  IconCls="button_delete">
        <ToolTips>
            <ext:ToolTip ID="tipDelete" runat="server" Html="Delete [Del]" AutoWidth="true" />
        </ToolTips>
        <DirectEvents>
            <Click OnEvent="delete_button">
                <ExtraParams>
                    <ext:Parameter Name="Event" Value=(event) Mode="Raw" />
                </ExtraParams>
            </Click>
        </DirectEvents>
    </ext:Button>
    With ExtraParameter you only can send text values.


    Thanks, and sorry, my english isn't very good.
  2. #2
    Hi,

    A client-side event handler in Ext.NET can be configured using a "Listener" config. The following sample from the Examples Explorer details several different options for configuring a Click Listener on a Button. Which method to choose will depend upon your requirements.

    https://examples1.ext.net/#/Events/Listeners/Overview/

    A few simple way of calling your JavaScript function is using the .OnClientClick property. The following sample demonstrates, although I'm not sure you need 'event' parameter with Ext.NET.

    Example

    <ext:Button ID="btnDelete" runat="server" IconCls="button_delete" OnClientClick="cancel_button();" />
    Hope this helps.
    Geoffrey McGill
    Founder
  3. #3
    Thanks, wow faster answer, now I can use the button just like with the after HTML Buttons.

    All the fuctiĆ³ns that don't have parameters works fine... but all the functiĆ³ns with "event parameter" send me and error. I think they are not sending the same info launching with Ext than the HTML Button.

    Error when calls this line: e.preventDefault();
    Microsoft JScript runtime error: Object doesn't support property or method 'preventDefault'
  4. #4
    Hi,

    Please provide a sample to reproduce that error.
  5. #5
    The ASPX Page Contains the Button:
    <ext:Button ID="btnDelete"  runat="server"  Icon="Delete" OnClientClick="delete_button(event)">
        <ToolTips>
            <ext:ToolTip ID="tipDelete" runat="server" Html="Delete [Del]" AutoWidth="true" />
        </ToolTips>
    </ext:Button>
    This Button Call this Script:

    function delete_button(e)
    {
    	//graph.deleteSelection();
    	//graph.update();
    	//graph.updateActiveObject(graph.pointerPosition);
    	//graph.updateMouseCursor();
    	graph.stopEvent(e);
    	//graph.update();
    };
    And with the same event, call this finally script:

    Graph.prototype.stopEvent = function (e) 
    {
    	e.preventDefault();
    	e.stopPropagation();
    };
    The problem happens with All Buttons that I send "event" as parameter.

    A complete Sample (most Simplified possible):
    <%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <!DOCTYPE html>
    
    <html>
    <head id="Head1" runat="server">
        <title>Dynamics Editor</title>
        <script runat="server">
            protected void Page_Load(object sender, EventArgs e)
            {
                
            }
        </script>
    
        <script type="text/javascript">
        var graph = null;
    
        function documentLoad() {
            graph = new Graph(document.getElementById("canvas"));
        };
    
        var Graph = function (element) {
            this.canvas = element;
            this.canvas.focus();
            this.context = this.canvas.getContext("2d");
            
            this.isWebKit = typeof navigator.userAgent.split("WebKit/")[1] !== "undefined";
            this.isMozilla = navigator.appVersion.indexOf('Gecko/') >= 0 || ((navigator.userAgent.indexOf("Gecko") >= 0) && !this.isWebKit && (typeof navigator.appVersion !== "undefined"));
        };
    
        Graph.prototype.stopEvent = function (e) {
            e.preventDefault();
            e.stopPropagation();
        };
    
        // Delete Seleccition
        function delete_button(e) {
            //graph.deleteSelection();
            //graph.update();
            //graph.updateActiveObject(graph.pointerPosition);
            //graph.updateMouseCursor();
            graph.stopEvent(e);
            //graph.update();
        };
        </script>
    </head>
    <body>
    	<form id="frmGraph" runat="server" method="post">
            <asp:HiddenField ID="txtCode" runat="server" />
            <asp:HiddenField ID="txtInfo" runat="server" />
    	</form>
    
    	<canvas id="canvas" class="graph" tabindex="-1" width="800" height="600" border="2"></canvas>
    
        <ext:ResourceManager ID="rmDinamicasTransaccionales" runat="server"> 
            <Listeners>
                <DocumentReady Handler="documentLoad(); " />
            </Listeners>
        </ext:ResourceManager>    
    
        <ext:Window ID="frmToolbar" 
            runat="server"
            Closable="false"
            AutoScroll="true"
            AutoHeight="true"
            Resizable="false"
            Width="245">
            <Listeners>
                <Show Handler=" this.el.alignTo(Ext.getBody(), 'b-b', [0,-22]); " />
            </Listeners>
            <Items>
                <ext:Toolbar ID="tbGraph" runat="server">
                    <Items>
                        <ext:ButtonGroup ID="bgOperations" runat="server" Title="<%$ Resources:LocalizedText, DinamicasTransaccionales_Toolbar_Titulo_Operaciones %>">
                            <Items>
                                <ext:Panel ID="pnlOperations" runat="server" Frame="true">
                                    <Items>
                                        <ext:ComboBox ID="cbOperationList" runat="server" Editable="false" SelectedIndex="0" AutoWidth="true">
                                            <Items>
                                                <ext:ListItem Value="X" Text="Value X" />
                                                <ext:ListItem Value="Y" Text="Value Y" />
                                            </Items>        
                                        </ext:ComboBox>
                                    </Items>
                                    <Buttons>
                                        <ext:Button ID="btnSave"    runat="server"  Icon="Disk" OnClientClick="save_button()">
                                            <ToolTips>
                                                <ext:ToolTip ID="tipSave" runat="server" Html="Save [Ctrl + S]" AutoWidth="true" />
                                            </ToolTips>
                                        </ext:Button>
                                        <ext:Button ID="btnCancel"  runat="server"  Icon="Cancel" OnClientClick="cancel_button(event)">
                                            <ToolTips>
                                                <ext:ToolTip ID="tipCancel" runat="server" Html="Cancel [Esc]" AutoWidth="true" />
                                            </ToolTips>
                                        </ext:Button>
                                        <ext:Button ID="btnAdd"     runat="server"  Icon="Add" OnClientClick="add_button()">
                                            <ToolTips>
                                                <ext:ToolTip ID="tipAdd" runat="server" Html="Add [Alt + '+']" AutoWidth="true" />
                                            </ToolTips>
                                        </ext:Button>
                                        <ext:Button ID="btnDelete"  runat="server"  Icon="Delete" OnClientClick="delete_button(event)">
                                            <ToolTips>
                                                <ext:ToolTip ID="tipDelete" runat="server" Html="Delete [Del]" AutoWidth="true" />
                                            </ToolTips>
                                        </ext:Button>
                                        <ext:Button ID="btnUndo"    runat="server"  Icon="ArrowUndo" OnClientClick="undo_button(event)">
                                            <ToolTips>
                                                <ext:ToolTip ID="tipUndo" runat="server" Html="Undo [Ctrl + z]" AutoWidth="true" />
                                            </ToolTips>
                                        </ext:Button>
                                        <ext:Button ID="btnRedo"    runat="server"  Icon="ArrowRedo" OnClientClick="redo_button(event)">
                                            <ToolTips>
                                                <ext:ToolTip ID="tipRedo" runat="server" Html="Redo [Ctrl + y]" AutoWidth="true" />
                                            </ToolTips>
                                        </ext:Button>
                                    </Buttons>
                                </ext:Panel>
                            </Items>
                        </ext:ButtonGroup>
                    </Items>
                </ext:Toolbar>
            </Items>
        </ext:Window>
    </body>
    </html>
  6. #6
    I don't think that the sample reproduces the problem you've faced.

    I'm getting "undo_button is undefined" JS error when trying to click on the button and the same with another button.

    So, I can't see where you defined these JS functions.

    Also please clarify why do you need to call "stopPropagation" and "preventDefault" methods? I can't see any reason to do this.

    Anyways, you could call it using:
    Ext.EventObject.preventDefault();
    See also
    http://docs.sencha.com/ext-js/3-4/#!...xt.EventObject
  7. #7
    Try with Delete Button, please. I'm only add this button to simplify the sample.
  8. #8
    You should replace "event" with "e".
    delete_button(e)
  9. #9
    Yes!!! Work perfect!!!

    Thanks Daniil and geoffrey

Similar Threads

  1. Call JavaScript function with CellSelection
    By bolzi89 in forum 1.x Help
    Replies: 5
    Last Post: Dec 23, 2011, 2:42 PM
  2. How to call the javascript function form code behind
    By harshad.jadhav in forum 1.x Help
    Replies: 3
    Last Post: Mar 29, 2011, 3:00 PM
  3. Replies: 6
    Last Post: Mar 11, 2011, 5:30 AM
  4. [CLOSED] Call Javascript Function
    By speedstepmem4 in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Jul 21, 2010, 3:58 AM
  5. Replies: 1
    Last Post: Jun 03, 2009, 12:10 PM

Tags for this Thread

Posting Permissions