This is a migrated thread and some comments may be shown as answers.

Error when drilling

3 Answers 74 Views
OrgChart
This is a migrated thread and some comments may be shown as answers.
Ed Staffin
Top achievements
Rank 1
Ed Staffin asked on 08 Aug 2012, 08:21 PM

I got what I thought was a really simple example to test the drilldown capability of the orgchart, but I'm getting an errror:
Sys.WebForms.PageRequestManagerServerErorrException :Object reference not set to an instance of an object.
I get this when I click on the little icon next to someone's name to drill down.
The page comes up fine and displays the chart, so I know there's nothing wrong with the query.
Here's the bare bones code:
Thanks ... Ed

<%@ Page Title="" Language="C#" MasterPageFile="~/Default.master" AutoEventWireup="true" CodeFile="TestOrgChart.aspx.cs" Inherits="SysAdmin_TestOrgChart" %>
<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
<asp:Content ID="Content1" ContentPlaceHolderID="cntHead" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="cntPageBody" Runat="Server">
    <telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server" >
        <telerik:RadOrgChart runat="server" ID="org1" EnableDrillDown="true">
 
        </telerik:RadOrgChart>
</telerik:RadAjaxPanel>
 
 
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;
using MyDB;
 
public partial class SysAdmin_TestOrgChart : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LoadChart();
        }
    }
    private void LoadChart()
    {
        MyDataContext db = new MyDataContext();
            var qry = from a in db.STAFFs
                      select new { a.STAFF_SEQ,
                                          a.PARENT_STAFF_SEQ,
                                          FullName = a.LAST_NAME + ", " + a.FIRST_NAME };
 
 
            org1.DataSource = qry.ToDataTable();
            org1.DataFieldID = "STAFF_SEQ";
            org1.DataFieldParentID = "PARENT_STAFF_SEQ";
            org1.DataTextField = "FullName";
            org1.DataBind();
            org1.DisableDefaultImage = true;
    }
}
 
  
</asp:Content>


3 Answers, 1 is accepted

Sort by
0
Ed Staffin
Top achievements
Rank 1
answered on 09 Aug 2012, 12:10 PM
I think I figured it out, but I don't get it.
Apparently, in my Page_Load event I had:
if(!IsPostBack) 
    LoadChart();

Silly me, thinking that I only needed to call that once.
It seems that it needs to get called each time a postback occurs?!?!
This means I have to make a call to the db and rebind each time a postback happens?
Seems to me I should only have to bind once.
Am I missing something?
Thanks ... Ed

0
Peter Filipov
Telerik team
answered on 10 Aug 2012, 12:53 PM
Hello Ed,

We designed the RadOrgChart not to implement ViewState with the idea to be as light as possible. Because of this you need to rebind the control on every postback. For the future releases we could consider implementing ViewState.

Regards,
Peter Filipov
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Ed Staffin
Top achievements
Rank 1
answered on 10 Aug 2012, 01:02 PM
Hi,
Thanks for the response. Perhaps I would suggest a property -- UseViewState.
This way I can make the choice. In my app I store viewstate on the server anyhow, so I don't care how big it gets.
Just a thought.
Thanks ... Ed
protected override void SavePageStateToPersistenceMedium(object viewState)
  {
      System.IO.FileStream theFile = default(System.IO.FileStream);
      string sPath = null;
      StreamWriter sw = default(StreamWriter);
      LosFormatter fmt = new LosFormatter();
      sPath = Server.MapPath("~/Viewstate");
      try
      {
          theFile = File.Open(sPath + "\\MyApp_" + Session.SessionID + ".dat", FileMode.OpenOrCreate);
          theFile.SetLength(0);
          sw = new StreamWriter(theFile);
          fmt.Serialize(sw, viewState);
          sw.Close();
 
      }
      catch (Exception ex)
      {
          throw new System.Exception("Unhandled Error in SavePageStateToPersistenceMedium(). Please contact technical support. Error Description:" + ex.Message, ex);
      }
  }
 
  protected override object LoadPageStateFromPersistenceMedium()
  {
 
      System.IO.FileStream theFile = null;
      string sPath = null;
      string sViewState = null;
      object vs = null;
      StreamReader sr = default(StreamReader);
      LosFormatter fmt = new LosFormatter();
      sPath = Server.MapPath("~/Viewstate");
      try
      {
          if (File.Exists(sPath + "\\MyApp_" + Session.SessionID + ".dat") == false)
          {
              Session.Abandon();
              Response.Redirect("~/Default.aspx");
          }
          else
          {
              theFile = File.Open(sPath + "\\MyApp_" + Session.SessionID + ".dat", FileMode.Open);
              sr = new StreamReader(theFile);
              sViewState = sr.ReadToEnd();
              sr.Close();
              vs = fmt.Deserialize(sViewState);
              return vs;
          }
          theFile.Close();
      }
      catch (Exception ex)
      {
          throw new System.Exception("Unhandled Error in LoadPageStateFromPersistenceMedium(). Please contact technical support. Error Description:" + ex.Message, ex);
      }
      return vs;
  }

Tags
OrgChart
Asked by
Ed Staffin
Top achievements
Rank 1
Answers by
Ed Staffin
Top achievements
Rank 1
Peter Filipov
Telerik team
Share this question
or