More in this section
Forums / General Discussions / Object reference not set to an instance of an object

Object reference not set to an instance of an object

The forums are in read-only mode. In case that you want to directly contact the Progress Sitefinity team use the support center. In our Google Plus group you can find more than one thousand Sitefinity developers discussing different topics. For the Stack Overflow threads don’t forget to use the “Sitefinity” tag.
2 posts, 0 answered
  1. Randy Evanchick
    Randy Evanchick avatar
    1 posts
    31 Dec 2009
    07 Apr 2010
    Link to this post
    II am creating a control that is referencing a asp:Panel control.
    If I insert the below code into an aspx file it works fine.

    Any help on this would be great.

    Sample of code below. 
    (Main ascx file)
    01.<asp:DetailsView ID="detailform1" runat="server" DataSourceID="qrygeteventinfo"
    02.            AutoGenerateRows="False" GridLines="None" HorizontalAlign="Left"
    03.            Width="400px" CellPadding="4" ForeColor="#333333" DefaultMode="ReadOnly">
    06.                <asp:TemplateField ShowHeader="False" ConvertEmptyStringToNull="False" InsertVisible="True">
    07.                <ItemTemplate>
    09.                <table>
    10.                <tr id="Tr1" runat="server">
    11.                <td align="right">
    12.                   <asp:Panel ID="editpanel" runat="server">
    13.                        <a href="/SEFCUBoardCalendar/BoardCalendarEdit.aspx?id=<%# Eval("C_Event_id") %>">Edit</a>
    14.                 </asp:Panel>
    16.            </td>
    18.  </tr>
    20.    </ItemTemplate>
    21.  </asp:TemplateField>
    22.  </Fields>
    23. </asp:DetailsView>

    (ascx.cs)  code behind file

    01.if (sqldr.HasRows)
    02.            {
    03.                sqldr.Read();
    04.                Panel myeditpanel = detailform1.FindControl("editpanel") as Panel;
    06.                int userid = Convert.ToInt16(sqldr["PersonIdNo"]);
    07.                switch (userid)
    08.                {
    09.                    case 1:
    10.                       //   Code Fails on the line below. 
    12.                        myeditpanel.Visible = false;
    13.                        break;
    14.                    default:
    15.                        myeditpanel.Visible = false;
    16.                        break;
    17.                }
    18.            }

  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    12 Sep 2017
    13 Apr 2010
    Link to this post
    Hi Randy Evanchick,

    Some of the variables that you use returns null. You could attach the code to VS debugger and see which item returns null. Basically it seem that you are not checking for null, but you are using this object. In the code snippet that you send I do not see any line that you ensure that nulls will be escaped.

    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
2 posts, 0 answered