How to have scripts inside UserControl?

  1. #1

    How to have scripts inside UserControl?

    I'm trying to create a UserControl but can't quite figure out how to get scripts to work inside. The code I'm using is below. The nodeLoad is not working, even though this same code works if in a regular aspx page. Am I missing something here? I really need the scripting to be contained within the control, not outside of it.

    <%@ Control Language="VB" AutoEventWireup="false" CodeFile="FolderView.ascx.vb" Inherits="FolderView" %>
    <%@ Register Assembly="Coolite.Ext.Web" Namespace="Coolite.Ext.Web" TagPrefix="ext" %>
    
    
    
    <style type="text/css">
        .x-tree-node .x-tree-node-inline-icon{background:transparent;height:16px;width:16px;}
    </style>
    <script type="text/javascript">
        function nodeLoad(node) {
            Coolite.AjaxMethods.LoadFolder(node.id, {
                success: function(result) {
                var data = eval("(" + result + ")");
                    node.loadNodes(data);
                },
                failure: function(errorMsg) {
                    Ext.Msg.alert('Failure', errorMsg);
                }
            });
        }
        function nodeClear(node) {
            while (node.hasChildNodes()) {
                node.removeChild(node.item(0));
            }
        }        
    </script>
     
    <ext:FitLayout ID="FitLayout1" runat="server">
        <ext:TreePanel ID="TreePanel1" runat="server" Border="false" Animate="false">
            <Listeners>
                <BeforeLoad Fn="nodeLoad" />
            </Listeners>
        </ext:TreePanel>
    </ext:FitLayout>
  2. #2

    RE: How to have scripts inside UserControl?

    Hi,

    If you define AjaxMethod in INamingContainer (MasterPage, UserControl) then you need use ClientID of in ajax method javascript name
    Coolite.AjaxMethods.ClientIDOfUserControl.MyMethod();

    In 0.8 version you can define own rules which name must be with AjaxMethodProxyIDAttribute and AjaxMethodNamespace
    Also in 0.8 you can use #{AjaxMethods} which will use current context automatically (detect what currect context and add required prefixed (like ClientID) automatically)
    #{AjaxMethods}.MyMethod();
  3. #3

    RE: How to have scripts inside UserControl?

    This seems to work now. So until v0.8, how do I possibly do this if the user control will be used in various places throughout the application with different ids? Do I have to hard code every possible name of the user control?
  4. #4

    RE: How to have scripts inside UserControl?

    Your code sample seems like it should work.

    Where are you defining the AjaxMethod "Coolite.AjaxMethods.LoadFolder"?


    If the "LoadFolder" Mehtod is defined in the UserControl code-behind, does your sample work if you add the .ClientID of the UserControl before .LoadFolder?


    Example


    Coolite.AjaxMethods.<%= this.ClientID %>.LoadFolder

    Hope this helps.


    Geoffrey McGill
    Founder

Similar Threads

  1. Replies: 8
    Last Post: Feb 15, 2012, 9:04 AM
  2. Help with UserControl inside window
    By dbassett74 in forum 1.x Help
    Replies: 0
    Last Post: May 26, 2009, 4:25 PM
  3. [CLOSED] Get ext control inside UserControl
    By methode in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Dec 22, 2008, 1:24 PM
  4. Autosize GridPanel inside UserControl
    By petlun in forum 1.x Help
    Replies: 3
    Last Post: Dec 19, 2008, 6:16 PM
  5. [CLOSED] Usercontrol inside a form layout
    By jchau in forum 1.x Legacy Premium Help
    Replies: 4
    Last Post: Nov 03, 2008, 1:57 PM

Posting Permissions