Exception Details: System.NullReferenceException: Object reference not set to an instance of an object comes when try to set scroll bar as true in telerik chart code

Thread is closed for posting
2 posts, 0 answers
  1. Vinod
    Vinod avatar
    1 posts
    Member since:
    Jun 2011

    Posted 09 Jun 2011 Link to this post

    Hello Sir,

    I was trying to create a chart with scroll bar so that we can see maximum chart but when we set scroll bar is true then websites gives null reference error message and when we set scroll bar as null then it is working fine.

    Please find the error message as:

    Object reference not set to an instance of an object.
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

    Source Error:

    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. 

    Stack Trace:

    [NullReferenceException: Object reference not set to an instance of an object.]
       Telerik.Web.ScriptObjectBuilder.RegisterCssReferences(Control control) +257
       Telerik.Web.UI.RadChart.OnPreRender(EventArgs e) +64
       System.Web.UI.Control.PreRenderRecursiveInternal() +103
       System.Web.UI.Control.PreRenderRecursiveInternal() +175
       System.Web.UI.Control.PreRenderRecursiveInternal() +175
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2496


    Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.1

    Please find the details code which i have written and help me to resolve this issue.


    //---------------Default aspx.vb------------------//

    Imports System
    Imports System.Data
    Imports System.Configuration
    Imports System.Collections
    Imports System.Web
    Imports System.Web.Security
    Imports System.Web.UI
    Imports System.Web.UI.WebControls
    Imports System.Web.UI.WebControls.WebParts
    Imports System.Web.UI.HtmlControls
    Imports System.Data.SqlClient
    Imports Telerik.Charting


    Partial Public Class Chart_Examples_Skinning_Bars_DefaultCS
        Inherits System.Web.UI.Page

        Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
            If Not Page.IsPostBack Then
                RadChart1.Skin = "Default"
            End If
        End Sub
        Private Sub PopulateSkins()
            If Not Page.IsPostBack Then
                Dim skinsList As New ArrayList()
                skinsList.AddRange(New String() {"Black", "Default", "Hay", "Inox", "Office2007", "Outlook", "Sunset", "Telerik", "Vista", "Web20", "WebBlue", "Marble", "Metal", "Wood", "BlueStripes", "DeepBlue", "DeepGray", "DeepGreen", "DeepRed", "GrayStripes", "GreenStripes", "LightBlue", "LightBrown", "LightGreen"})
                ThumbsList.DataSource = skinsList
            End If
        End Sub
        Protected Sub OrientationList_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
            RadChart1.SeriesOrientation = DirectCast([Enum].Parse(GetType(ChartSeriesOrientation), OrientationList.SelectedValue), ChartSeriesOrientation)
        End Sub
        Protected Sub SubtypeDropdown_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
            RadChart1.Series(0).Type = DirectCast([Enum].Parse(GetType(ChartSeriesType), SubtypeDropdown.SelectedValue), ChartSeriesType)
            RadChart1.Series(1).Type = DirectCast([Enum].Parse(GetType(ChartSeriesType), SubtypeDropdown.SelectedValue), ChartSeriesType)
        End Sub
        Protected Overloads Overrides Sub OnPreRender(ByVal e As EventArgs)
            For Each item As ListItem In ThumbsList.Items
                item.Text = String.Format("<img src='thumbnails/{0}.gif' alt='' onclick='if(this.parentNode.click)this.parentNode.click();'/> {0}", item.Value)
        End Sub
        Protected Sub ThumbsList_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
            RadChart1.Skin = ThumbsList.SelectedValue
        End Sub


        Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

            RadChart1.ClientSettings.ScrollMode = Telerik.Web.UI.ChartClientScrollMode.XOnly
        End Sub

        Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
            Dim connectionString As [String] = "Data Source = IN-GGS-VINOD\MSSQLSERVER1; Initial Catalog=LibraryManagementSystem;Integrated Security = True;"
            Dim selectCommand As String = "SELECT top 200 [Facility] ,[TodaysChart],[YesterdaysChart]  FROM [LibraryManagementSystem].[dbo].[Facility]"
            Dim dataAdapter As New SqlDataAdapter(selectCommand, connectionString)
            Dim table As New DataTable()
            RadChart1.DataSource = table
            RadChart1.PlotArea.XAxis.DataLabelsColumn = "Facility"
            AddHandler RadChart1.DataBound, AddressOf radChart1_DataBound
            RadChart1.SeriesOrientation = ChartSeriesOrientation.Horizontal
            RadChart1.Series(0).Type = ChartSeriesType.StackedBar
            RadChart1.Series(1).Type = ChartSeriesType.StackedBar

        End Sub
        Private Sub radChart1_DataBound(ByVal sender As Object, ByVal e As EventArgs)
            RadChart1.Series(0).DataYColumn = "TodaysChart"
            ' assign appearance related properties
            radChart1.PlotArea.XAxis.Appearance.LabelAppearance.RotationAngle = 300
            radChart1.PlotArea.XAxis.Appearance.TextAppearance.TextProperties.Color = System.Drawing.Color.BlueViolet
            RadChart1.PlotArea.Appearance.Dimensions.Margins.Bottom = Telerik.Charting.Styles.Unit.Percentage(20)
            RadChart1.PlotArea.Appearance.Dimensions.Margins.Left = Telerik.Charting.Styles.Unit.Percentage(20)

            RadChart1.SeriesOrientation = ChartSeriesOrientation.Horizontal
            RadChart1.Series(0).Type = ChartSeriesType.StackedBar
            RadChart1.Series(1).Type = ChartSeriesType.StackedBar

        End Sub


    End Class


    <%@ Page Language="vb" AutoEventWireup="true" CodeFile="Default.aspx.vb" Inherits="Chart_Examples_Skinning_Bars_DefaultCS" %>

    <%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
    <%@ Register TagPrefix="telerik" Namespace="Telerik.Charting" Assembly="Telerik.Web.UI" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <body class="BODY">
        <form id="Form1" runat="server">
            <asp:ScriptManager ID="ScriptManager" runat="server" />
            <div id="MainPlaceHolder">
                <div id="ChartArea">
               <div id="chartOptionsPlaceholder">
                        <asp:Button ID="Button1" runat="server" Text="PopulateChart" />
                        <asp:Button ID="Button2" runat="server" Text="NewPopulateChart" />
                        <br />
                        <asp:Label ID="lblChartOrientation" runat="server" Text="Series orientation:" />
                        <asp:RadioButtonList AutoPostBack="true" ID="OrientationList" runat="server" OnSelectedIndexChanged="OrientationList_SelectedIndexChanged">
                            <asp:ListItem Text="Horizontal" Value="Horizontal" />
                            <asp:ListItem Text="Vertical" Value="Vertical" Selected="True" />
                        <br />
                        <asp:Label ID="lblChartType" runat="server" Text="Additional chart types:" />
                        <asp:DropDownList AutoPostBack="true" ID="SubtypeDropdown" runat="server" OnSelectedIndexChanged="SubtypeDropdown_SelectedIndexChanged">
                            <asp:ListItem Text="Normal Bar" Value="Bar" Selected="True" />
                            <asp:ListItem Text="Stacked Bar" Value="StackedBar" />
                            <asp:ListItem Text="Stacked Bar 100" Value="StackedBar100" />
                    <div id="chartPlaceholder">
                        <telerik:RadChart ID="RadChart1" SkinsOverrideStyles="true" runat="server"
                           Width="1038px" AutoLayout="true">

                        <ClientSettings EnableZoom="false" ScrollMode=Both />
                 <telerik:ChartSeries Name="series 1" Type="Bar">
                 <telerik:ChartSeriesItem YValue="3" XValue="0" />
                 <telerik:ChartSeriesItem YValue="3" XValue="1" />
                 <telerik:ChartSeriesItem YValue="4" XValue="3" />
                 <telerik:ChartSeriesItem YValue="3" XValue="3" />
                 <telerik:ChartSeriesItem YValue="5" XValue="4" />
                 <telerik:ChartSeries Name="series 2" Type="Bar">
                 <telerik:ChartSeriesItem YValue="1" XValue="5" />
                 <telerik:ChartSeriesItem YValue="2" XValue="4" />

                    <XAxis DataLabelsColumn="Code1"></XAxis>
                    <TextBlock Text="Previous Vs Current Period" />
                <div id="ThumbsArea">
    <asp:RadioButtonList ID="ThumbsList" AutoPostBack="true" runat="server" RepeatColumns="3"
    RepeatDirection="Horizontal" OnSelectedIndexChanged="ThumbsList_SelectedIndexChanged">
            <div class="qsfClearFloat"><!-- --></div>

  2. Tsvetie
    Tsvetie avatar
    1517 posts

    Posted 14 Jun 2011 Link to this post

    Hello Vinod,
    I created a simple test page, based on the code that you have provided in order to try to reproduce the exception. Unfortunately, I was not able to reproduce it with my test page - please, find it attached. The only change that I had to make to your code, was the connection to the database and table name, as I did not have your database.

    In case my code does not help you, please open a formal support ticket and send me a running test project that demonstrates the error, together with detailed information on the steps I need to follow in order to reproduce it.

    All the best,
    the Telerik team

    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

Back to Top