Calling with App.XXXX on js causes null references

  1. #1

    Calling with App.XXXX on js causes null references

    When i try to do something like this on the example https://examples2.ext.net/#/Chart/Pie/Basic/ for show the Tips when the js function it's called causes a null reference to the ID of the chart. I checked the ID on the ext chart control and it's the same on both (the js function and the control). however i try with others controls and when i try call them with App.IDofmycontrol it's the same problem i receive this null exception (cheked with firebug). I have made all i need on differents ways to avoid use the call of my controls with App.IdOfMyContol but now i have the same problem on excecution time with code behind, when i try do something like this

    aspx file
    ....
    <ext:Label runat="server" ID="label1" />
    ....

    aspx.cs file
    in some part of code i try modify a propiety of the label1
    label1.Text = "some text";
    or
    label1.Show();
    i receive the same error on the script debuger of visual studio on execution time from the eval code
    Exception:

    0x800a138f - Error in JavaScript runtime: Unable to get the 'setText' property null reference or undefined

    the part of code generated dinamically:
    App.Cuerpo_label1.setText("some text",true);
    i have to configure the app resourcemanager of some way?
    Last edited by Prybe; Aug 13, 2014 at 6:00 PM.
  2. #2

    I found my error

    I've solved checking all my code and i forget add an ext:store who's i'm using on some controls. But i still have the problem with custom scripts calling controls through App.IdOfControl
  3. #3
    Hi @Prybe,

    Welcome to the Ext.NET forums!

    But i still have the problem with custom scripts calling controls through App.IdOfControl
    I could look at a test case if you provide.
  4. #4
    Thanks Danil!


    <script type="text/javascript">
            var tipRenderer = function (storeItem, item) {
                var total = 0;
                App.pieChart.getStore().each(function (rec) {//in this line when i debug with firebug the calling to the piechart control produces null exception 
    
                    total += rec.get('Number');
                });
                
                this.setTitle(storeItem.get('Text') + ': ' + Math.round(storeItem.get('Number') / total * 100) + '%');
            };
    
    /*     the modified function
            var tipRenderer = function (storeItem, item, pieChart, tipRender) {
                var total = 0;
                pieChart.getStore().each(function (rec) {
                    total += rec.get('Number');
                });
                tipRender.setTitle(storeItem.get('Text') + ': ' + Math.round(storeItem.get('Number') / total * 100) + '%');
            };
            */
    
    </script>
    <ext:ResourceManager ID="ResourceManager1" runat="server" Theme="Gray" DirectMethodNamespace="SIP_DE" />
    ...some of code
    <ext:Chart ID="pieChart" runat="server"
                                    ColumnWidth="0.5"
                                    Height="350"
                                    Animate="true"
                                    Shadow="true"
                                    Theme="Base:gradients" 
                                    AutoSize="true">
                                    <LegendConfig Position="Left" />
                                    <Store>
                                        <ext:Store ID="storeIndicadorGP" 
                                            runat="server" 
                                            AutoDataBind="true">                           
                                            <Model>
                                                <ext:Model ID="Model3" runat="server">
                                                    <Fields>
                                                        <ext:ModelField Name="Number"  Mapping="Number"/>
                                                        <ext:ModelField Name="Text" Mapping="Text"/>
                                                    </Fields>
                                                </ext:Model>
                                            </Model>
                                        </ext:Store>
                                    </Store>
                                    <Series>
                                        <ext:PieSeries 
                                            AngleField="Number" 
                                            ShowInLegend="true" 
                                            Donut="0" 
                                            Highlight="true" 
                                            HighlightSegmentMargin="20">
                                            <Label Field="Text" Display="Rotate" Contrast="true" Font="10px Arial" />
                                            <Tips runat="server" ID="Tips1" TrackMouse="true" Width="240" Height="28">
                                                <Renderer Fn="tipRenderer" />
                                                <%--
                                                 with this commented line and the respective "modified function"  it works fine, but i still have the doubt about why i can't make it like in the examples
                                                <Renderer Handler="tipRenderer(storeItem, item, #{pieChart}, this)" />
                                                 --%>
                                            </Tips>
                                        </ext:PieSeries>
                                    </Series>
                                </ext:Chart>
    Attached Thumbnails Click image for larger version. 

Name:	Sin nombre.jpg 
Views:	15 
Size:	100.5 KB 
ID:	14231  
  5. #5
    Do you use a MasterPage? Or, maybe, the Chart is inside a UserControl?
  6. #6
    Yes i use a master page
  7. #7
    A ContentPlaceHolder implements the INamingContainer interface, therefore the client ids/references looks like:
    App.ContentPlaceHolderID_pieChart
    But there is a better way to access the Chart inside the tipRenderer function:
    item.series.chart
  8. #8

    Solved

    Thank Daniil it works great both solutions.
    I have to mark like solved? if yes how i do that?
    Last edited by Prybe; Aug 14, 2014 at 5:20 PM.
  9. #9
    Nice.

    Do not worry, we mark it by our own and only on the Premium or Bugs forums.

Similar Threads

  1. Replies: 0
    Last Post: May 21, 2012, 1:42 PM
  2. Replies: 6
    Last Post: Nov 24, 2011, 12:47 PM
  3. Replies: 1
    Last Post: Nov 24, 2011, 10:51 AM
  4. Replies: 1
    Last Post: Jun 08, 2010, 11:38 AM
  5. Replies: 3
    Last Post: Jan 10, 2010, 1:42 PM

Tags for this Thread

Posting Permissions