Link to home
Start Free TrialLog in
Avatar of Tom Knowlton
Tom KnowltonFlag for United States of America

asked on

Ways to resolve this error

Error	403	The name 'ctrlOrganizationAddSpecialities' does not exist in the current context	72	13	C:\TFS\UnionNet\UnionNet\Common\OrganizationAddSpecialtyLicensesByClassification.aspx.cs	Common

Open in new window


What is the source of this error?

How can it be resolved, short of creating a brand new web form and attempting to place the control on it?
Avatar of Shaun Kline
Shaun Kline
Flag of United States of America image

Which version of .Net are you using? .Net v1.1 had this issue, where control declarations were not always generated and you had to manually add it.

Did you add the control directly to the "HTML" without clicking over to the UI Design side? This can cause .Net to not add the control declaration to the class partial portion that contains all of the declarations for your controls.

Did you remove a control and not remove a reference to it in code?
Avatar of Tom Knowlton

ASKER

version of .NET:  VS 2010 .. .NET Framework:  3.5


It even does it when I create a brand new winform and put the control on it...I just tried it just now....

Can the partial class be modified...manually?

Can I force the controls to link?
Is the control an ASCX page? Does it exist on a master page?

If you can provide the code for the function where the error occurs, and the portion of the ASPX page there the control is defined, we can provide more pointed assistance.
Sure thing:


MAIN FORM MARKUP:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="OrganizationAddSpecialtiesLicensesByClassification.aspx.cs" Inherits="UnionNet.Common.OrganizationAddSpecialtiesLicensesByClassification"  MasterPageFile="../UnionNet.Master" %>

<%@ Register TagPrefix="asp" Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" namespace="System.Web.UI" %>

<%@ Register src="Common/OrganizationAddSpecialtiesControl.ascx" tagname="OrganizationAddSpecialtiesControl" tagprefix="uc1" %>

<asp:Content ID="dialogContent" ContentPlaceHolderID="DialogContent" runat="server">
    
        <uc1:OrganizationAddSpecialtiesControl ID="OrganizationAddSpecialtiesControl1" 
            runat="server" />
    
   </asp:Content>

Open in new window







MAIN FORM CODE BEHIND:

NOTE:  You'll see that I have commented-out this line:

ctrlOrganizationAddSpecialities


If I do -- my code compiles.


If I uncomment the line ... the error comes back.


using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using NetEndeavor.Utilities;

using UnionNet.Framework;
using UnionNet.Security;

namespace UnionNet.Common
{
    public partial class OrganizationAddSpecialtiesLicensesByClassification : UnionNetPage
    {
        #region Members
        private UnionNetDialog _MasterPage;
        private int _ID;
        private int _EntID;
        private int _ModuleKey = 0;

        private string _IsReadOnly = "false";


        #endregion

        #region OnPreInit
        protected override void OnPreInit(EventArgs e)
        {
            MasterPageFilePath = UNFRAMEWORK_DIALOG_MASTER;

            base.OnPreInit(e);
        }
        #endregion

        #region OnInit
        protected override void OnInit(EventArgs e)
        {
            _ModuleKey = UnionNetUtilityMethods.GetQueryStringInt("mid");

            string isRO = UnionNetUtilityMethods.GetQueryStringValue("readOnly");
            _IsReadOnly = isRO.Length > 0 ? UnionNetUtilityMethods.GetQueryStringValue("readOnly") : "false"; ;

            switch (_ModuleKey)
            {
                case ApplicationModuleIDs.Research:
                    PageResourceRight = ResourceRights.FieldReports_Projects_Manage;
                    break;

                case ApplicationModuleIDs.FieldReports:
                    PageAddResourceRight = ResourceRights.FieldReports_Projects_Manage;
                    PageEditResourceRight = ResourceRights.FieldReports_Projects_Manage;
                    PageViewResourceRight = ResourceRights.FieldReports_Projects_View;
                    break;

                default:
                    PageResourceRight = ResourceRights.FieldReports_Projects_Manage;
                    break;
            }

            base.OnInit(e);

            _ID = UnionNetUtilityMethods.GetQueryStringInt("id");
            _EntID = UnionNetUtilityMethods.GetQueryStringInt("entID");
            //ctrlOrganizationAddSpecialities.OrganizationID = _ID;
           // ctrlOrganizationAddSpecialities.EntityID = _EntID;
           // ctrlOrganizationAddSpecialities.IsReadOnly = _IsReadOnly == "false" ? false : true;

            _MasterPage = (UnionNetDialog)Master;
            _MasterPage.DialogMode = _ID > 0 ? DialogModes.Edit : DialogModes.New;
            if (_ID > 0)
                _MasterPage.Title = String.Format(GetString("ORGANIZATION_DETAIL", true), GetString("EDIT"));
            else
                _MasterPage.Title = String.Format(GetString("ORGANIZATION_DETAIL", true), GetString("NEW"));


            _MasterPage.OKButtonClick += new OKButtonEventHandler(OnSave);

            _MasterPage.HelpButton.Visible = false;

        }
        #endregion

        #region Page_Load
        protected override void Page_Load(object sender, EventArgs e)
        {
            base.Page_Load(sender, e);
        }
        #endregion

        #region OnPreRender
        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);

            RegisterClientScripts();


            if (_ID > 0)
            {
                // this resets the window title, but should not change the dialog header...
                //




          //      _MasterPage.Title = ctrlOrganizationAddSpecialities.OrganizationData.Name + " - " + String.Format(GetString("ORGANIZATION_DETAIL", true), GetString("EDIT"));



            }

        }
        #endregion

        #region OnSave
        void OnSave(object sender, EventArgs e)
        {
            int newID = _ID;

            Organization org = null;
            RuntimeHelpers.PrepareConstrainedRegions();
            try
            {
                org = new Organization();
                org.Load(_ID);

                OrganizationData orgData = org.Data;

            //    ctrlOrganizationAddSpecialities.Save(ref orgData);

                org.CurrentUser = CurrentUser;
                org.Data = orgData;



                if (!org.Validate())
                {
                    MessageBox(org.ValidationMessage,
                        MessageBoxButtonType.OK,
                        MessageBoxIconType.Exclaimation);

                    return;
                }


                if (NEError.NE_SUCCESS != org.Save(_ID))
                {
                    MessageBox(GetString("CRITICAL_ERROR"),
                        MessageBoxButtonType.OK,
                        MessageBoxIconType.Critical);

                    return;
                }

                newID = org.ID;
            }
            finally
            {
                if (!object.Equals(null, org))
                {
                    org.Dispose();
                }
            }

            ClientScript.RegisterClientScriptBlock(GetType(),
                "organizationDetail",
                "<script language='javascript'>window.returnValue=" + newID.ToString() + "; window.close();</script>");

        }
        #endregion


        #region RegisterClientScripts
        private void RegisterClientScripts()
        {
            //            string scripts = @"
            //			";
            //            ClientScript.RegisterClientScriptBlock(GetType(), "organization_edit_scripts", scripts, true);
        }
        #endregion
    }
}

Open in new window








USER CONTROL MARKUP:
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="OrganizationAddSpecialtiesControl.ascx.cs"
    Inherits="UnionNet.Common.OrganizationAddSpecialtiesControl" %>
<%@ Register TagPrefix="asp" Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
    Namespace="System.Web.UI" %>
<%@ Register TagPrefix="unc" Namespace="UnionNet.Framework" Assembly="UnionNetFramework" %>
<%@ Register TagPrefix="cc" Namespace="UnionNet.Framework" Assembly="UnionNetFramework" %>
<style type="text/css">
    
</style>
<div id="col1" style="float: left; width: 380px; border-right: 1px dotted #c8c8c8;
    padding: 0 8px 0 0; margin: 0 8px 0 0;">    
    <div class="FormRow">
        <cc:UNLabel ID="UNLabelLicenseClassifications" runat="server" Width="93"></cc:UNLabel>
        <unc:UNDropDown ID="UNDropDownLicenseClassifications" runat="server"  Width="257px" Required="NotRequired" />
    </div>    
</div>

Open in new window








USER CONTROL CODE BEHIND:
//-----------------------------------------------------------------------
//     OrganizationAddSpecialtiesControl.aspx.cs 
//     Copyright (c) Net Endeavor, Inc.  All rights reserved.
//-----------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using NetEndeavor.Utilities;

using UnionNet.Framework;
using UnionNet.Security;

namespace UnionNet.Common
{
	public partial class OrganizationAddSpecialtiesControl : UnionNetControl
	{
		#region Properties
		private OrganizationData _OrganizationData = new OrganizationData();
		public OrganizationData OrganizationData
		{
			get { return _OrganizationData; }
			set { _OrganizationData = value; }
		}
        
        private int _OrganizationID = 0;
		public int OrganizationID
		{
			get { return _OrganizationID; }
			set { _OrganizationID = value; }
		}

		private int _EntityID = 0;
		public int EntityID
		{
			get { return _EntityID; }
			set { _EntityID = value; }
		}

		private bool _IsReadOnly = false;
		public bool IsReadOnly
		{
			get { return _IsReadOnly; }
			set { _IsReadOnly = value; }
		}


		#endregion


		#region OnInit
		protected override void OnInit(EventArgs e)
		{
			base.OnInit(e);
		}

		#endregion

		#region Page_Load
		protected void Page_Load(object sender, EventArgs e)
		{
			if ( !IsPostBack )
			{
				WindowSession.AddRemoveSessionItem( SessionKeys.ORGANIZATION_DATA );				
			}
			else
			{
				_OrganizationData = (OrganizationData)WindowSession.Get( SessionKeys.ORGANIZATION_DATA );				
			}


            if (!IsPostBack)
            {
                UNLabelLicenseClassifications.Text = GetString("SIGNATORY_STATUS");
                UnionNetListCollection.PopulateList(UNDropDownLicenseClassifications.Items, CurrentUser.UserID, 0, "", UnionNetListType.SignatoryStatus);
                UNDropDownLicenseClassifications.SelectedValue = _OrganizationData.SignatoryStatusID.ToString();
            }
		}
		#endregion


		#region OnPreRender
		protected override void OnPreRender(EventArgs e)
		{
			base.OnPreRender(e);
		}
		#endregion


		#region LoadDialogData
		private void LoadDialogData()
		{
			if ( _OrganizationID == 0 )
			{
				_OrganizationData = new OrganizationData();

				_OrganizationData.IsActive = true;
				_OrganizationData.IsValid = true;
				_OrganizationData.ID = -1;

				if ( _EntityID > 0 )
				{
					ProjectEntity entity = null;
					try
					{
						entity = new ProjectEntity();
						if ( NEError.NE_SUCCESS != entity.Load( _EntityID ) )
							throw new Exception( "Error loading project entity in OrganizationEdit.aspx" );

						_OrganizationData.IsConversion = true;
						_OrganizationData.Name = entity.Name;

			
					}
					finally
					{
						if ( !object.Equals( null, entity ) )
							entity.Dispose();
					}
				}
			}
			else
			{
				Organization organization = null;
				try
				{
					organization = new Organization();
					if ( NEError.NE_SUCCESS != organization.Load( _OrganizationID ) )
						throw new Exception( "Error loading organization in OrganizationEdit.aspx" );

					_OrganizationData = organization.Data;
				}
				finally
				{
					if ( !object.Equals( null, organization ) )
						organization.Dispose();
				}
			}

			WindowSession.Add( SessionKeys.ORGANIZATION_DATA, _OrganizationData );			

		}
		#endregion

		#region Save
		public void Save( ref OrganizationData organization )
		{
            //organization = _OrganizationData;

            //organization.SignatoryStatusID  = Convert.ToInt32(UNDropDownLicenseClassifications.SelectedValue);
            //organization.SignatoryStatus    = UNDropDownLicenseClassifications.SelectedItem.Text;
            //organization.dayAgreementStartDate = DateTime.Parse(UNDateRangeAgreement.Value);
            //organization.dayAgreementEndDate = DateTime.Parse(UNDateRangeAgreement.Value2);
            //organization.dayLiabilityInsuranceDate = UNCalendarLiabilityDate.Date;
            //organization.dayWorkersCompensationDate = UNCalendarWorkersComp.Date;
            //organization.ParentOrganizationID = Convert.ToInt32(luParentOrg.ObjectID);
            //organization.OrganizationDBA = UNTextBoxDBA.Text;


            //organization.Addresses		= (List<AddressData>)WindowSession.Get(SessionKeys.ADDRESS_LIST);
            //organization.PhoneNumbers	= (List<PhoneNumberData>)WindowSession.Get(SessionKeys.PHONE_LIST);
		}
		#endregion	
	}
}

Open in new window

Is the control an ASCX page? Does it exist on a master page?

Yes .. the control is an ascx page.

It is being placed on a web form that DOES have a master page, yes.
ASKER CERTIFIED SOLUTION
Avatar of Shaun Kline
Shaun Kline
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
When you defined the control on the ASPX page, the ID is OrganizationAddSpecialtiesControl1, which should be the way to reference it in the code behind page. Does IntelliSense pick up ctrlOrganizationAddSpecialities or does it pick up OrganizationAddSpecialtiesControl1?

That was the problem...found it a few minutes ago <headslap/>
Well done!