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

NullPointerException in Grid while Updating.

5 Answers 150 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Grendizer
Top achievements
Rank 1
Grendizer asked on 12 Sep 2008, 03:26 PM

Hello all, specially Vlad ^_^

I have an issue for you. I encouter a NullPointerException with my grid.
As you will see in provided code, the grid is pretty simple, with EditMode set to /InPlace/, and it allows column sizing ...

I apologize in advance if this issue has already been raised, but I haven't seen related stuff in the existing threads ... except perhaps an old thread concerning an old version of the control with different behavior [ Bizarre Grid Behavior ]

In my case, the Edit/Update process works well, and the sizing process seems to do what it supposed to do as well .. with a little bemol here, but that's not the point of this topic ... The issue appears when you try to mix both, I mean click on Edit and while editing you resize any column .. then after when you try to validate your changes by clicking the Update link .. the exception is raised.

Same result in the opposite way, if you resize a column and after that click on Edit it breaks ... That's seems pretty ugly, because I cannot mix resize and edit ... :-(

At first it was javascript exception : Sys.WebForms.PageRequestManagerServerErrorException : Object reference not set to an instance of an object.

Much interesting call stack with Ajax disabled :

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

Stack Trace:

[NullReferenceException: Object reference not set to an instance of an object.]
   Telerik.Web.UI.RadGrid.LoadClientState(Dictionary`2 clientState) +7509
   Telerik.Web.UI.RadCompositeDataBoundControl.LoadPostData(String postDataKey, NameValueCollection postCollection) +193
   Telerik.Web.UI.RadCompositeDataBoundControl.System.Web.UI.IPostBackDataHandler.LoadPostData(String postDataKey, NameValueCollection postCollection) +42
   System.Web.UI.Page.ProcessPostData(NameValueCollection postData, Boolean fBeforeLoad) +693
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1743


Here the aspx definition.

<telerik:RadGrid ID="RadGridCommunication" runat="server"    
    EnableViewState="False" 
    AutoGenerateColumns="False" 
    OnNeedDataSource="RadGridCommunication_NeedDataSource"   
    GridLines="None" 
    Skin="Office2007"                                              
    AllowPaging="True" 
    PageSize="3" 
    ShowStatusBar = "true"                                              
    > 
      
    <MasterTableView   
        CommandItemDisplay"Top" 
        EditMode="InPlace" 
        > 
        <Columns> 
            <telerik:GridEditCommandColumn  UniqueName="EditCommandColumn" /> 
            <telerik:GridBoundColumn DataField="Name" HeaderText="Name" DataFormatString="<nobr>{0}</nobr>" /> 
            <telerik:GridBoundColumn DataField="Age" HeaderText="Age" DataFormatString="<nobr>{0}</nobr>" /> 
            <telerik:GridBoundColumn DataField="Email" HeaderText="Email" DataFormatString="<nobr>{0}</nobr>"/>  
            <telerik:GridBoundColumn DataField="Phone" HeaderText="Phone"  DataFormatString="<nobr>{0}</nobr>"/>  
        </Columns> 
          
        <CommandItemStyle  CssClass="gridCommandBar" />   
        <CommandItemTemplate> 
            <div style="float: left">    
                <asp:Label ID="Label1" CssClass="blockTitleForm" runat="server"  EnableViewState="False" >Communication Medium</asp:Label> 
            </div> 
            <div style="float: right">    
               <asp:LinkButton Style="vertical-align: bottom" ID="btnEditSelected" runat="server" EnableViewState="False"   
                CommandName="EditSelected" Visible='<%# RadGridCommunication.EditIndexes.Count == 0 %>' 
                > 
                <img style="border:0px" alt="" src="../im/btnGoToPage_01.png" / title="Edit selected item" EnableViewState="False"  >   
            </asp:LinkButton> 
            </div> 
              
          
        </CommandItemTemplate>                                                  
    </MasterTableView> 
    <ClientSettings AllowColumnsReorder="true" > 
        <ClientEvents OnCommand="RadGridCommunication_Command" /> 
        <Resizing   
        AllowColumnResize="True"   
        AllowRowResize="false"   
        ResizeGridOnColumnResize="false"                                                      
        ClipCellContentOnResize="true"   
        EnableRealTimeResize="false" /> 
    </ClientSettings> 
    <StatusBarSettings LoadingText="Loading ..." ReadyText ="Ready"/>                                              
</telerik:RadGrid> 

then the code behind taken from some Kevin Babcock samples :

[WebMethod]  
public static IEnumerable<NWA.POC.Models.Contact> GetData()  
{  
    var path = HttpContext.Current.Server.MapPath(@"Data\contacts.xml");  
    var xml = System.Xml.Linq.XDocument.Load(path)  
                       .Descendants("Contact");  
 
    var contacts = from contact in xml  
                   select new NWA.POC.Models.Contact  
                   {  
                       ID = Convert.ToInt32(contact.Element("ID").Value),  
                       Name = contact.Element("Name").Value,  
                       Age = Convert.ToInt32(contact.Element("Age").Value),  
                       Sex = contact.Element("Sex").Value,  
                       Email = contact.Element("Email").Value,  
                       Phone = contact.Element("Phone").Value  
                   };  
 
    return contacts;  

Thanks in advance for your answer.

5 Answers, 1 is accepted

Sort by
0
Nikolay Rusev
Telerik team
answered on 16 Sep 2008, 09:01 AM
Hello Grendizer,

I am afraid I cannot reproduce the error you received.
You can find the attached project to this post and run it on your end. You will see that while RadGrid is in edit mode and resize the columns no error will be raised.

Regards,
Nikolay
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Grendizer
Top achievements
Rank 1
answered on 16 Sep 2008, 01:17 PM
Hello Nikolay,

first of all, thanks for your answer, and for the sample web site.

That's really strange .. by using your sample and pasting the content of the original ASPx page, I was unable to reproduce the issue which still exist on my original solution.

I'll Try to find out the source of the issue and let you know.

Thanks
0
Grendizer
Top achievements
Rank 1
answered on 17 Sep 2008, 09:18 AM
Hello Nikolay,

I'm back with some news, I finally managed to reproduce the issue within your provided solution by simply disabling the ViewState in the page directive :

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default"  EnableViewState="false"  %> 

Thanks to let me know about this issue as soon as possible, as we plan to purchase the library within the next weeks but our page design doesn't allow viewState ... so I need to have a clear idea on that kind of issue.

Hope this helps.
0
Grendizer
Top achievements
Rank 1
answered on 17 Sep 2008, 09:27 AM
Just to complete & summarize the post, the issue is raised when the page viewState is disable :
* resizing the column then click on Edit
* click on Edit then try to resize a column
* resizing the column then do a postBack within the grid or using any another control like an asp:LinkButton

It seems pretty obvious that there is an issue in the state management.

Hope this helps.
0
Accepted
Nikolay Rusev
Telerik team
answered on 17 Sep 2008, 02:47 PM
Hello Grendizer,

Unfortunately you are right. I was able to reproduce the error.

Since you are not using ViewState I suggest you rebind grid control on PageInit to have the resizing functionality work properly.

You can use the following code snippet to accomplish that:
protected override void OnInit(EventArgs e)  
    {  
        base.OnInit(e);  
        RadGridCommunication.Rebind();  
    } 

Best regards,
Nikolay
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Grid
Asked by
Grendizer
Top achievements
Rank 1
Answers by
Nikolay Rusev
Telerik team
Grendizer
Top achievements
Rank 1
Share this question
or