Need Helep with Error Rendering Control on ascx User control pages


I am trying to learn how to write code to develop web pages using ASP.Net.  On a web user control called movement.ascx, I am getting a "Error Rendering Control" An unhandled exception Object reference not set to an instance of an object"

Now I need help and I am paying for help with this site $12.95 monthly.  When I ask questions I want help.  Please do not respond to my questions with an address link to researched pages.  I can do this on my own without your help.  

If you know how to help me, please do specifically and explain what to do to solve the problem.  Remember, I am not an expert.  I am an amateur trying to piece together.
So do not assume I know what you mean.

Anyhow:  My code again movement.ascx.

In design view, I get the error rendering control.  The application works completely.
I just want to get rid of the error rendering control message in the design view.

The Code:

<%@ Control Language="VB" AutoEventWireup="false" CodeFile="Movement.ascx.vb" Inherits="Controls_Movement" %>

< %@ Register Assembly="DOC" Namespace="DOC.Controls" TagPrefix="DOC" %>
< %@ Register Src="~/Controls/Movement/inmateGroup.ascx" TagName="inmateGroup" TagPrefix="IMAS" %>
< %@ Register Src="~/Controls/Movement/HoldingBin.ascx" TagName="HoldingBin" TagPrefix="IMAS" %>
< %@ Register Src="~/Controls/VerifyPassword.ascx" TagName="VerifyPassword" TagPrefix="IMAS" %>
< %@ Register Src="~/Controls/Movement/Confirmation.ascx" TagName="Confirmation" TagPrefix="Movement" %>

< script type="text/javascript">
function inmateSearch() {document.location.href = '<%=InmateSearchHref%>';}
< /script>

< div id="saveButton" runat="server" style="display:inline;">
<input type="button" id="cmdSave" runat="server" value="Save" disabled="disabled" style="width:100px;margin:10px 0px 0px 6px;"/>
< /div>

< DOC rogressindicator id="ProgressIndicator1" runat="server"/>
< IMAS:VerifyPassword ID="VerifyPassword1" runat="server" RefreshOnPageLoad="true"/>
< DOC:InmateValidator id="InmateValidator1" runat="Server" RefreshOnPageLoad="false"/>

< DOC:ProgressIndicator id="ProgressIndicator" runat="server"/>

< div id="rootElement" runat="server" style="position:absolute;z-index:101;left:5px;top:5px;width:99%;height:600px;">

<Movement:Confirmation ID="MovementConfirmation1" runat="server" RefreshOnPageLoad="false"/>

<table cellpadding="0" cellspacing="8" border="0"
style="position:relative;top:-10px;left:-5px; height: 865px;">
<td style="width:416px;"><IMAS:InmateGroup ID="InmateGroup1" runat="server"/></td>
<td style="width:416px;"><IMAS:InmateGroup ID="InmateGroup2" runat="server"/></td>
<td colspan="2">
<IMAS:HoldingBin ID="HoldingBin1" runat="server"/>

<input type="text" id="txtDuration" value="0" style="display:none" />

<!-- Hide template elements -->
<div class="templates" style="display:none">
<!-- DropCue Template -->
<div id="dropCueTemplate" class="dropCue">Drop?</div>
<!-- Empty Template -->
<div id="emptyTemplate" class="emptyList"></div>
<div id="emptyInmateTemplate"></div>
<div id="divInmateSearch" runat="server" style="position:absolute;top:0px;left:850px;z-index:1200;">
<img src="~../Images/InmateSearch.gif"
onmousedown= "changeButtonImage('../Images/InmateSearch_mousedown.gif');" alt="Search for an Inmate"
< /div>

Please help.

Who is Participating?

Improve company productivity with a Business Account.Sign Up

esolveConnect With a Mentor Commented:
Theres a few things missing. What is this and where is it declared?

Control = rootElement
InstID = Master.InstID

I pressume the following comes from the master page. Do you have the masterpage set?


You will get and object reference not set error if you do not have a querystring (AIS) in the URL
Rather do this:

If Not Request.QueryString("AIS") = nothing
 AIS = Request.QueryString("AIS")
End if

There could be an error in this method


This will also cause an error if you do not have this value in the web.config file

The rest looks ok
The object reference error you get is because you are accessing a member variable from the code behind page. Also you are accessing this variable using asp3.0 code.

I have also found this very frustrating. Visual Studio does eventually resolve this but sometimes seems to take ages to pick up that the variable does actually exists in the code behind page.

Please ensure you have this variable "InmateSearchHref" properly declared in your code behind page like this.

public InmateSearchHref as String

Also ensure that this variable gets set eg. in the page load event.

InmateSearchHref = "http://whateeryoururl.aspx"

Another aproach would be to set the attributes in the code behind.

Dim redirectURL as String
img.Attributes.Add("onclick", "inmateSearch(" + redirectURL + ");");

Then you wont get this error. Just ensure that your img has an id attribute and the runat=server is set.

O and obviously you need to change your javascript method to accept the redirect parameter.

function inmateSearch(url) {
 document.location.href = url;
Obadiah ChristopherCommented:
For me, such issues get resolved, once I click on html in Design View and press F7.
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

jjc9809Author Commented:

I am going to try your solutions when I return to work Tuesday after the holiday. I believe your solution wll help me after reading it.  But, all of my ascx pages in design view have these same error rendering controls, but the entire application is working.  There is a problem dropping inmates into the holding bin which is another problem in its self.

jjc9809Author Commented:
What are you accomplishing by selecting design view and selecting F7?  What does this mean?

Obadiah ChristopherCommented:
Basically when in design mode the variables do not get updated, if I do a Right Click and click on View Code, the variables get updated properly. i.e. if I change the textbox name/id and it is not reflected.

Anyway, this is just a suggestion.
jjc9809Author Commented:

This is what I have shown on my code behind page, Movement.ascx.vb.

Imports System.Web.UI

Partial Class Controls_Movement

    Inherits DOC.IMAS.MovementControl_BinAndHousingUnitList

    Public AIS As String
    Public InmateSearchHref As String
    Public InmateGroups As New ArrayList

    Public Overrides Sub Refresh()
        Control = rootElement
        ScriptClassName = "DOC.IMAS.Movement.Movement"
        ScriptFilePath = "~/script/DOC.IMAS.Movement.Movement.js"

        AIS = Request.QueryString("AIS")
        InstID = Master.InstID



        AddClientProperty("bins", SerializeBins)
        AddClientProperty("housingUnits", SerializeHousingUnits)
        AddClientProperty("instID", InstID)
        AddClientProperty("locationID", Master.LocationID)
        AddClientProperty("AIS", AIS)

        AddDomElement("cmdSave", cmdSave.ClientID)
        AddDomElement("divMasterTitleBar", Master.TitleBar.ClientID)

        AddObjectReference("inmateValidator", InmateValidator1.Control.ClientID)
        AddObjectReference("movementConfirmation", MovementConfirmation1.Control.ClientID)
        AddObjectReference("verifyPassword", VerifyPassword1.Control.ClientID)

        AddObjectReferenceArray("inmateGroups", InmateGroups)

        InmateSearchHref = ConfigurationManager.AppSettings("DocFind") & "Default.aspx?Target=" + Server.UrlEncode(Request.Path.Replace("MovementPopup", "Movement")) & "&InstID=" & InstID
    End Sub

    Private Sub _InitializeControls()
        'TODO: POSSIBLE script reference conflict
        'Master.AddScriptReference(ConfigurationManager.AppSettings("ApplicationRoot") & "/ASD_Web_Handler.ashx?2;DOC, Version=, Culture=neutral, PublicKeyToken=null::DOC.DOC.Controls.Inmate.js")





        With InmateGroup1
            .Bins = Bins
            .HousingUnits = HousingUnits
            .Partner = InmateGroup1
        End With

        With InmateGroup2
            .Bins = Bins
            .HousingUnits = HousingUnits
            .Partner = InmateGroup2
        End With

        With HoldingBin1
        End With
    End Sub

End Class

Maybe this coding can more show what I am trying to do.

jjc9809Author Commented:

Let me send you other files.  Yes, I do have a MasterPage Set.  Please find additional Web User Control Pages which go along with the Movement.ascx.  There is a folder named Movement.  Under this folder in the project, I have (1).  Confirmation.ascx, (2).  HoldingBin.ascx, (3).  InmateGroup.ascx, (4).  InmateGroup.ascx, (5).  InMateGroupSourceSelector.ascx., (6).  and of course Movement.ascx which I have already sent you.  There is one addtional file under the Movement folder,  which is (7).  ToolBar.ascx.  

Please find MasterPage.vb and Page.vb which is stored under a folder called Pages included as well.  I have attached the web configuration.Test.

You will have to  be more specific.

Each of these controls of yours inherits from other files.

eg. Inherits DOC.IMAS.MovementControl_BinAndHousingUnitList
eg. Inherits DOC.IMAS.AjaxUserControl

I cannot recreate your whole project with what you have provided me and it would not be possible to identify the error if I only have 10% of the objects.
jjc9809Author Commented:

I wonder if the entire project can be sent to you.  It is quite large.  I will just have to be more specific as you said.  Let me see what I can do further.
jjc9809Author Commented:

The error rendering errors does not affect the application running.  All User Controls and web pages appear to be running as they should.  I have been told to not concentrate on these errors and to just look at the Movement page and see what is wrong there with movement of an inmate to the control bin.

The main objective here is to upgrade and convert  the application to the 3.5 Dot Net Framework.  THe application has been published in the 2.0 Dot Net Framework with VS 2005  and is working fine in production.  However, VS 2008 R2 is going to be used now in the future.
I am getting these error rendering on the controls when the application in VS 2005 is converted to the VS 2008 R2 using the 3.5 Dot Net Framework.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.