+1-888-365-2779
Try Now
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

2 posts, 0 answered
  1. Randy Evanchick
    Randy Evanchick avatar
    1 posts
    Registered:
    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">
    04.<Fields>
    05.           
    06.                <asp:TemplateField ShowHeader="False" ConvertEmptyStringToNull="False" InsertVisible="True">
    07.                <ItemTemplate>
    08. 
    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>
    15.                 
    16.            </td>
    17.                 
    18.  </tr>
    19.</table>
    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;
    05.    
    06.                int userid = Convert.ToInt16(sqldr["PersonIdNo"]);
    07.                switch (userid)
    08.                {
    09.                    case 1:
    10.                       //   Code Fails on the line below. 
    11. 
    12.                        myeditpanel.Visible = false;
    13.                        break;
    14.                    default:
    15.                        myeditpanel.Visible = false;
    16.                        break;
    17.                }
    18.            }

  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    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.

    Regards,
    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