[CLOSED] javascript error

  1. #1

    [CLOSED] javascript error

    I got this error using Firefox
    missing ; before statement
    in this code:
    Ext.onReady(function(){
    Ext.QuickTips.init();
    this.ctl00_menuLanguage=new Ext.menu.Menu({
        proxyId:"ctl00_menuLanguage",
        items:[
    
    new Ext.menu.CheckItem({id:"ctl00_ctl12",
        ajaxEvents:{
            click:{
                fn:function(el,e){
                    var params=arguments;
                    Coolite.AjaxEvent.confirmRequest({
                        extraParams:{language:"pt-PT"},
                        formProxyArg:"aspnetForm",
                        control:this
                    });
                }
            }
        },
        text:"Portuguese (Portugal)",
        group:"menuLanguages"
    }),
    
    new Ext.menu.CheckItem({
        id:"ctl00_ctl13",
        ajaxEvents:{
            click:{
                fn:function(el,e){
                    var params=arguments;
                    Coolite.AjaxEvent.confirmRequest({
                        extraParams:{language:"en-GB"},formProxyArg:"aspnetForm",control:this
                    });
                }
            }
        },
        text:"English (United Kingdom)",
        group:"menuLanguages",checked:true
    })
    ]});
    
    this.ctl00_ctl05=new Ext.menu.Menu({
        proxyId:"ctl00_ctl05",
        items:[
    
    new Ext.menu.Item({
        id:"ctl00_menuItemCustomers",
        iconCls:"icon-usersuit",
        href:"Customers.aspx",
        text:"Customers"}),
    new Ext.menu.Item({
        id:"ctl00_menuItemContactPersons",
        iconCls:"icon-group",
        href:"ContactPersons.aspx",
        text:"Contact Persons"}),
    new Ext.menu.Item({
        id:"ctl00_menuItemDocuments",
        iconCls:"icon-page",
        href:"Documents.aspx",
        text:"Documents"}),
    new Ext.menu.Separator({
        id:"ctl00_MenuSeparator1",
        xtype:"component"}),
    new Ext.menu.Item({
        id:"ctl00_menuItemLogout",
        ajaxEvents:{
            click:{
                fn:function(el,e){
                    var params=arguments;Coolite.AjaxEvent.confirmRequest({formProxyArg:"aspnetForm",control:this});
                }
            }
        },
        iconCls:"icon-group",
        text:"Logoff"}),
    new Ext.menu.Item({
        id:"ctl00_menuItemLanguage",
        hideMode:"visibility",
        menu:ctl00_menuLanguage,
        text:"English (United Kingdom)"})
    ]});
    
    this.ctl00_MainViewPort=new Coolite.Ext.Viewport({
        id:"ctl00_MainViewPort",
        renderTo:"aspnetForm",
        layout:"border",
        items:[{
            id:"ctl00_pnlMenu",
            region:"west",
            margins:"0 0 0 0",
            width:200,
            layout:"border",
            items:[{
                id:"ctl00_pnlLogo",
                region:"north",
                margins:"0 0 0 0",
                height:100,
                border:false,
                contentEl:"ctl00_pnlLogo_Body"
            },{
                id:"ctl00_menuMain",
                xtype:"coolitemenupanel",
                ctCls:"mainMenu",
                autoShow:true,
                region:"center",
                border:false,
                menu:ctl00_ctl05
            }]
        },{
            id:"ctl00_pnlMain",
            region:"center",
            margins:"0 0 0 0",
            layout:"border",
            items:[{
                id:"ctl00_pnlTitle",
                cls:"titleString",
                region:"north",
                margins:"5 5 5 5",
                height:60,
                border:false,
                bodyStyle:"background-color: #F0F0F0;",
                contentEl:"ctl00_pnlTitle_Body"
            },{
                id:"ctl00_pnlFooter",
                cls:"footerText",
                region:"south",
                margins:"0 5 5 5",
                border:false,
                contentEl:"ctl00_pnlFooter_Body"
            },{
                id:"ctl00_pnlContent",
                region:"center",
                margins:"0 5 5 5",
                border:false,
                contentEl:"ctl00_pnlContent_Body"
            }]
        }]
    });
    
    new Ext.menu.CheckItem({
        id:"ctl00_ctl10",
        ajaxEvents:{
            click:{
                fn:function(el,e){
                    var params=arguments;Coolite.AjaxEvent.confirmRequest({extraParams:{language:"pt-PT"},formProxyArg:"aspnetForm",control:this});
                }
            }
        },
        text:"Portuguese (Portugal)",
        group:"menuLanguages"
    })
    new Ext.menu.CheckItem({
        id:"ctl00_ctl11",
        ajaxEvents:{
            click:{
                fn:function(el,e){
                    var params=arguments;Coolite.AjaxEvent.confirmRequest({extraParams:{language:"en-GB"},formProxyArg:"aspnetForm",control:this});
                }
            }
        },
        text:"English (United Kingdom)",
        group:"menuLanguages"
    })
    
    Coolite.Ext.lazyInit([
        "ctl00_ctl12","ctl00_ctl13","ctl00_menuItemCustomers","ctl00_menuItemContactPersons","ctl00_menuItemDocuments","ctl00_MenuSeparator1","ctl00_menuItemLogout","ctl00_menuItemLanguage","ctl00_pnlLogo","ctl00_menuMain","ctl00_pnlMenu","ctl00_pnlTitle","ctl00_pnlFooter","ctl00_pnlContent","ctl00_pnlMain"
    ]);
    ctl00_MainViewPort.doLayout();
    ctl00_menuItemLanguage.setVisible(false);
    ctl00_ctl10.on("checkchange",function(item,checked){this.getCheckedField().setValue(checked ? "true" : "false");});
    ctl00_ctl11.on("checkchange",function(item,checked){this.getCheckedField().setValue(checked ? "true" : "false");});
    ctl00_ctl12.on("checkchange",function(item,checked){this.getCheckedField().setValue(checked ? "true" : "false");});
    ctl00_ctl13.on("checkchange",function(item,checked){this.getCheckedField().setValue(checked ? "true" : "false");});
    });
                
    Coolite.Ext.ScriptManagerUniqueID="ctl00$ScriptManager1";
    Ext.BLANK_IMAGE_URL="/ALAdmin/extjs/resources/images/gray/s-gif/coolite.axd";
    please note that this code was all on one line and I formatted it to look nicer but besides newlines and tabs I didn't change anything
    I think the problem is the missing ; after each " new Ext.menu.CheckItem "

  2. #2

    RE: [CLOSED] javascript error

    Hi,



    Can you post ASPX which produces that javascript code?
    *
  3. #3

    RE: [CLOSED] javascript error

    the aspx is simple:
        <ext:MenuItem runat="server" ID="menuItemLanguage" HideMode="Offsets">
            <Menu>
                <ext:Menu runat="server" ID="menuLanguage">
                </ext:Menu>
            </Menu>
        </ext:MenuItem>
    I do most of the stuff in back code:
        protected void Page_Load(object sender, EventArgs e)
        {
            ...
            FillLanguageBox();
        }
    
        protected void Page_PreRender(object sender, EventArgs e)
        {
            this.menuItemLanguage.SetVisible(!string.IsNullOrEmpty(Global.GetCurrentCountry()));
            FillLanguageBox();
            if (this.menuItemLanguage.Visible)
            {
                string currentLanguage = Session[SessionVars.CultureInfo].ToString();
                foreach (Coolite.Ext.Web.CheckMenuItem item in this.menuLanguage.Items)
                {
                    if (item.AjaxEvents.Click.ExtraParams["language"] == currentLanguage)
                    {
                        this.menuItemLanguage.Text = item.Text;
                        item.Checked = true;
                    }
                }
            }
        }
    
        private void FillLanguageBox()
        {
            if (!this.menuItemLanguage.Visible) return;
    
            this.menuLanguage.Items.Clear();
            System.Globalization.CultureInfo MyCultureInfo = Global.GetCurrentCulture();
            string CurrentlanguageName = MyCultureInfo.Name;
            string CurrentCountry = Global.GetCurrentCountry();
            System.Globalization.CultureInfo[] AvailableLanguages = Truvo.Tools.DisplayProperties.Language.AvailableLanguages;
            for (int i = 0; i < AvailableLanguages.Length; i++)
            {
                if (!AvailableLanguages[i].Name.EndsWith(CurrentCountry) &amp;&amp; AvailableLanguages[i].Name != Global.GetDefaultCulture()) continue;
    
                Coolite.Ext.Web.CheckMenuItem item = new Coolite.Ext.Web.CheckMenuItem();
                                                    
                item.Text = AvailableLanguages[i].DisplayName;
                item.Group = "menuLanguages";
                item.AjaxEvents.Click.Event += new Coolite.Ext.Web.ComponentAjaxEvent.AjaxEventHandler(item_Click);
                item.AjaxEvents.Click.ExtraParams.Add(new Coolite.Ext.Web.Parameter("language", AvailableLanguages[i].Name));
                this.menuLanguage.Items.Add(item);
            }
            this.menuItemLanguage.Visible = this.menuLanguage.Items.Count > 0;
        }
    
        void item_Click(object sender, Coolite.Ext.Web.AjaxEventArgs e)
        {
            string newLanguage = e.ExtraParams["language"];
            if (Session[SessionVars.CultureInfo] != null &amp;&amp; Session[SessionVars.CultureInfo].ToString() == newLanguage) return;
    
            Session[SessionVars.CultureInfo] = newLanguage;
            Truvo.Tools.DisplayProperties.Language.SavePreferredCulture(this.Page, Global.GetCurrentCulture());
        }
    now, I tested some more and only when I run the FillLanguageBox method in both Page_Load and Page_PreRender I get that error. If I only call it in Page_PreRender, then I get a javascript "object does not exist" error.
    If I only call it in the Pagae_Load then I don't get any errors but the menu is not updated.

    What I want is to update the menu after the item_Click ajax event is triggered.
  4. #4

    RE: [CLOSED] javascript error

    Hi,

    May be just update your menu items text at PreRender. Why need remove it and recreate again at PreRender? Just create it at PageLoad and update text at PreRender. And set for each menu item ID to ensure that items have same ID between requests because otherwise ASP.NET will set own dynamic id and can be situation (if you have different actions sequence) that one control has different ID's between requests.

    Creating items at PreRender is have no sense because it is too late for Coolite control

  5. #5

    RE: [CLOSED] javascript error

    *it is not only text update,after a user logs in, I need to insert the languages in the menu but based on country.
    so, for example, if the user is from Belgium, I need to display french, dutch and english.
    The login happens on an Ajax Event (which is attached to the "Login" button being clicked) and then I need to build the menu. The only possible choice to do this dinamically was to put it in the pre-render, cause the page load event was already run.
  6. #6

    RE: [CLOSED] javascript error

    Hi,

    CreatingCoolite controls during AjaxEvent is not supported. Plus creating controls at PreRender is impossible even during first page *load because it is too late for Coolite controls (that breaks ScriptManager config build sequence)*


  7. #7

    RE: [CLOSED] javascript error

    *What if I create it on page load and put everything in and then on preRender just hide the ones I don't need?
    Would that work?
  8. #8

    RE: [CLOSED] javascript error

    Hi,

    I think it should works


    ** *private Coolite.Ext.Web.Button button1;
    ** *private Coolite.Ext.Web.Button button2;** *
    ** *
    ** *protected void Page_Load(object sender, EventArgs e)
    ** *{** * * *
    ** * * *button1 = new Coolite.Ext.Web.Button{Text = "Dynamic Button1"};
    ** * * *button2 = new Coolite.Ext.Web.Button { Text = "Dynamic Button2" };
    ** * * *
    ** * * *this.Page.Form.Controls.Add(button1);
    ** * * *this.Page.Form.Controls.Add(button2);
    ** *}


    ** *protected override void OnPreRender(EventArgs e)
    ** *{
    ** * * *base.OnPreRender(e);
    ** * * *button1.Hidden = Ext.IsAjaxRequest;
    ** * * *button2.Hidden = !Ext.IsAjaxRequest;
    ** *}*


    Please note that controls will be created, just will be hidded by own render


Similar Threads

  1. [CLOSED] Javascript Error
    By adelaney in forum 2.x Legacy Premium Help
    Replies: 7
    Last Post: Jun 18, 2012, 8:54 PM
  2. [CLOSED] IE8 javascript error
    By Edward in forum 1.x Legacy Premium Help
    Replies: 6
    Last Post: Sep 20, 2010, 7:16 PM
  3. [CLOSED] [1.0] Javascript Error in IE8
    By Ben in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Apr 21, 2010, 4:10 PM
  4. [CLOSED] Javascript Error?
    By Etisbew in forum 1.x Legacy Premium Help
    Replies: 11
    Last Post: Oct 15, 2009, 12:43 PM
  5. [CLOSED] SVN JavaScript error
    By Timothy in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Sep 11, 2008, 6:53 PM

Posting Permissions