[CLOSED] What is the correct syntax for this?

Page 1 of 3 123 LastLast
  1. #1

    [CLOSED] What is the correct syntax for this?

    Here's an example that illustrates what I'm trying to do:

    <script type="text/javascript">
        var <%= Me.ClientID %>_theFunction = function() {
            alert('test');
        };
    </script>
            <ext:Button runat="server" Text="Test">
                <Listeners>
                    <Click Handler="<%= Me.ClientID %>_theFunction();" />
                </Listeners>
            </ext:Button>
    Last edited by geoffrey.mcgill; Apr 02, 2012 at 7:26 PM. Reason: [CLOSED]
  2. #2
    This seems to work for me.

    Example

    <%@ Page Language="C#" %> 
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    
    <!DOCTYPE html>
    <html>
    <head runat="server">
        <title>Ext.NET Examples</title>
    </head>
    <body>
    <form runat="server">
        <ext:ResourceManager runat="server" />
    
    
        <script type="text/javascript">
            var <%= Button1.ClientID %>_theFunction = function () {
                alert('test');
            };
        </script>
    
    
        <ext:Button ID="Button1" runat="server" Text="Test">
            <Listeners>
                <Click Handler="#{Button1}_theFunction();" />
            </Listeners>
        </ext:Button>
    </form>
    </body>
    </html>
    I'm assuming "Me" is the .ID of a Control on your Page.

    The <%= %> syntax is only for rendering text inline on the Page. Unfortunately it does not function the same way in ASP.NET Property setters.
    Geoffrey McGill
    Founder
  3. #3
    Here's another option which uses the <ext:XScript> block to allow for parsing of '#{}' tokens. With this sample, the same #{Button1} sytax is used on both parts.

    Example

    <%@ Page Language="C#" %> 
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    
    <!DOCTYPE html>
    <html>
    <head runat="server">
        <title>Ext.NET Examples</title>
    </head>
    <body>
    <form runat="server">
        <ext:ResourceManager runat="server" />
    
    
        <ext:XScript runat="server">
            <script type="text/javascript">
                var #{Button1}_theFunction = function () {
                    alert('test');
                };
            </script>
        </ext:XScript>
        
        <ext:Button ID="Button1" runat="server" Text="Test">
            <Listeners>
                <Click Handler="#{Button1}_theFunction();" />
            </Listeners>
        </ext:Button>
    </form>
    </body>
    
    </html>
    Hope this helps.
    Geoffrey McGill
    Founder
  4. #4
    I forgot to mention that this is sitting inside of an ascx control. The Me.ClientID is actually the client id of the control.

    What I'm trying to do, is have a way for a javascript function to be both callable from outside the control, and also uniquely apply to the control (there will be multiple copies of the same control on the page.
  5. #5
    Something like the following should work across any Page or UserControl.

    Example

    <%@ Page Language="C#" %> 
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    
    <!DOCTYPE html>
    <html>
    <head runat="server">
        <title>Ext.NET Examples</title>
    </head>
    <body>
    <form runat="server">
        <ext:ResourceManager runat="server" />
    
    
            <script type="text/javascript">
                var <%= this.ClientID %>_theFunction = function () {
                    alert('test');
                };
            </script>
        
        <ext:Button ID="Button1" runat="server" Text="Test">
            <Listeners>
                <Click Handler='<%# this.ClientID + "_theFunction();" %>' AutoDataBind="true" />
            </Listeners>
        </ext:Button>
    </form>
    </body>
    </html>
    Hope this helps.
    Geoffrey McGill
    Founder
  6. #6
    Thanks Geoffrey!
  7. #7
    I'd love it if there were something like #{Me} or #{this} that would work similar to #{DirectMethods}. If you guys don't want to add it to Ext.net, is there a way for me to add it to my project so that I can make it a little easier to use?
  8. #8
    This should work right?

           <ext:Button runat="server" Text="Confirm" Icon="Accept">            <DirectEvents>
                    <Click OnEvent="TheButton_Click" Before='<%# "return " & Me.ClientID & "_theFunction();" %>' />
                </DirectEvents>
            </ext:Button>
  9. #9
    Quote Originally Posted by jmcantrell View Post
    This should work right?

           <ext:Button runat="server" Text="Confirm" Icon="Accept">            <DirectEvents>
                    <Click OnEvent="TheButton_Click" Before='<%# "return " & Me.ClientID & "_theFunction();" %>' />
                </DirectEvents>
            </ext:Button>
    Yes, but you need to either call .DataBind() on the Button, or set AutoDataBind="true" on the DirectEvent config.

    Hope this helps.
    Geoffrey McGill
    Founder
  10. #10
    Quote Originally Posted by jmcantrell View Post
    I'd love it if there were something like #{Me} or #{this} that would work similar to #{DirectMethods}. If you guys don't want to add it to Ext.net, is there a way for me to add it to my project so that I can make it a little easier to use?
    We'll discuss and get back to you.
    Geoffrey McGill
    Founder
Page 1 of 3 123 LastLast

Similar Threads

  1. [CLOSED] DateField: How to disable auto correct?
    By nhg_itd in forum 1.x Legacy Premium Help
    Replies: 4
    Last Post: Dec 08, 2011, 8:14 AM
  2. [CLOSED] Syntax to set EmptyText
    By vali1993 in forum 1.x Legacy Premium Help
    Replies: 12
    Last Post: Jan 24, 2011, 6:48 PM
  3. [CLOSED] GridPanel: correct way to get the row number
    By asztern in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Sep 09, 2010, 11:48 AM
  4. [CLOSED] [1.0] Syntax error.
    By gokcemutlu in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Feb 02, 2010, 7:07 AM
  5. [CLOSED] [0.8.2] PagingToolbar Not Showing Correct Total
    By rcaunt in forum 1.x Legacy Premium Help
    Replies: 6
    Last Post: Nov 25, 2009, 10:58 AM

Posting Permissions