none
Visual Studio 2015 Code-Behind (codeFile) does not seem to be locating controls(objects) in associated ASPX

    Question

  • I am creating a website in Visual Studio's 2015 with two pages.

    I have 2 webpages (index.aspx and index2.aspx) both pages have page control at top with their perspective CodeFile="index.aspx.cs" and CodeFile="index2.aspx.cs".

    also Inherits index and index2.

    There are buttons, validation, texboxes, and labels on the index page, the index2 page only has a label. 

    When I go to the code page, for some reason the pull downs gray out the controls in the third box over.

    Fist select list -  wk4_site_cs

    second  - index  (usually this is where the controls are listed, at least for VB.NET)

    third - has the controls but they are grayed out.  if I select one i get  

    "The definition of the object is hidden"

    I have tried a lot of different solution online, clear cache, reinstall VS, add controls, change controls, and since it is a website no design file.

    If I am in designer on the aspx page and double click a control it adds a object/control with event to the file, but this only works for items I can click.  I typed in the protected void statements for textChange and Load, and when I run website the code is not initiated because it can't seem to associate it with the button.

    Everything was working fine till I did update 3 to visual studios last week. 

    Old programs don't work anymore either, and creating new projects I get the same issue.

    I saw other post about this but those solutions never worked and were for older version of VS.  I am using 2015 with update 3.

    any Ideas how to fix this.


    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    
    public partial class index: System.Web.UI.Page
    
    protected void Page_Load(object sender, EventArgs e)
        {
    
        }
    
        
        protected void btnSave_Click(Object sender, EventArgs e)
        {
            //initiates counter, each time save is clicked counter iterates up and saves to session
    
    
    
            int counter = 0;
    
            if (Session["count"] != null)
            {
                counter = Convert.ToInt32(Session["count"]);
    
    
            }
            else
            {
                counter = 0;
    
    
    
            }
    
            counter = counter + 1;
            Session["count"] = counter;
        }
    
        protected void txbState_TextChanged(Object sender, EventArgs e)
        { //converts lowercase letters to upper case
            txbState.Text = txbState.Text.ToUpper();
        }
    
    
        protected void btnCounter_Click1(object sender, EventArgs e)
        {
            //opens new webpage
            Response.Redirect("index2.aspx");
        }
    
        protected void btnclear_Click1(object sender, EventArgs e)
        {
            //clears all textboxes
    
    
            txbFirst.Text = String.Empty;
            txbLast.Text = String.Empty;
            txbPassword.Text = String.Empty;
            txbState.Text = String.Empty;
        }
    
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="index.aspx.cs" Inherits="index" %>
    
    <!DOCTYPE html>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
         <title>User Registration </title>
     <link href="/css/StyleSheet.css" rel="stylesheet" type="text/css" />
    
    
    
    
    
    </head>
    
        
    
    <body>
        <form id="form1" runat="server">
      <div id="div1left" >
    
                   </div>
             
        
         <div id="div2center">
             <br/>
             
             <div id="divMain">
             
           
             <section id="sectop">
            
                  <asp:Label ID="lbltitle" runat="server" Text="User Registration"></asp:Label>   
           
              </section>
             <section id="secmiddle">
              
                  <asp:Label ID="lblFirst"  CssClass="lblReginfo" runat="server" Text="First Name:"></asp:Label>
                    <asp:RequiredFieldValidator ID="rfvFirst" ValidationGroup="Form1" Text="*" CssClass="valReginfo" ControlToValidate="txbFirst" runat="server" ErrorMessage="Must Enter First Name" Display="Dynamic"></asp:RequiredFieldValidator>
                 <asp:TextBox ID="txbFirst"  CssClass="txbReginfo" ValidationGroup="Form1" runat="server">  </asp:TextBox>
                     
                    
                 <asp:Label ID="lblLast" CssClass="lblReginfo" runat="server" Text="Last Name:"></asp:Label>
                     <asp:RequiredFieldValidator ID="rfvLast" ValidationGroup="Form1" Text="*" CssClass="valReginfo" ControlToValidate="txbLast" runat="server" ErrorMessage="Must Enter Last Name" Display="Dynamic"></asp:RequiredFieldValidator>
                 <asp:TextBox ID="txbLast"  CssClass="txbReginfo" ValidationGroup="Form1" runat="server"> </asp:TextBox>
                    
                   
                 <asp:Label ID="lblState"  CssClass="lblReginfo" runat="server" Text="State 2 Letter Abreviation:"></asp:Label>
                     <asp:RequiredFieldValidator ID="rfvState" ValidationGroup="Form1" Text="*" CssClass="valReginfo" ControlToValidate="txbState" runat="server" ErrorMessage="State Empty" Display="Dynamic"></asp:RequiredFieldValidator>
                     <asp:RegularExpressionValidator ID="revState" ValidationGroup="Form1" Text="*" ValidationExpression="[a-zA-Z]{2}" CssClass="valReginfo" ControlToValidate="txbState" runat="server" ErrorMessage="Enter a 2 Letter State Code"></asp:RegularExpressionValidator>
                  <asp:TextBox ID="txbState" CssClass="txbReginfo" ValidationGroup="Form1" AutoPostback="true" runat="server">  </asp:TextBox>
                    
                 <asp:Label ID="lblPassword"  CssClass="lblReginfo" runat="server" Text="Password 5 numbers:"></asp:Label>
                     <asp:RequiredFieldValidator ID="rfvPassword" ValidationGroup="Form1" Text="*" CssClass="valReginfo" ControlToValidate="txbPassword" runat="server" ErrorMessage="Password Empty" Display="Dynamic"></asp:RequiredFieldValidator>
                     <asp:RegularExpressionValidator ID="revPassword" ValidationGroup="Form1" Text="*" ValidationExpression="[0-9]{5}" CssClass="valReginfo" ControlToValidate="txbPassword" runat="server" ErrorMessage="Must Enter a 5 number password"></asp:RegularExpressionValidator> 
                 <asp:TextBox ID="txbPassword" CssClass="txbReginfo" ValidationGroup="Form1" runat="server" ></asp:TextBox>
                   
                 
                 
                  </section>
               
               
             
                  <section id="secbottom">
                  <asp:Button ID="btnSave" ValidationGroup="Form1" runat="server" Text="Submit" OnClick="btnSave_Click" />
                  <asp:Button ID="btnCounter" ValidationGroup="Form2" CauseValidation="false" runat="server" Text="Registration Count" OnClick="btnCounter_Click1" />
                 </section>
                  <section id="seclast">
                      <asp:Button ID="btnclear" ValidationGroup="Form2" CauseValidation="false" runat="server" Text="Clear" OnClick="btnclear_Click1" />
                         <asp:ValidationSummary ID="ValidationSummary1" ValidationGroup="Form1" runat="server" />
             
                       </section>
                 
                 
                 
             </div>
           </div>
                  
         <div id ="div3right">
         </div>
        </form>
    </body>
    </html>
    
    
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="index2.aspx.cs" Inherits="index2" %>
    <!DOCTYPE html>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title># of User Registration</title>
         <link href="/css/StyleSheet.css" rel="stylesheet" type="text/css" />
    </head>
    <body>
        <form id="form1" runat="server">
         <div id="div1left">
            </div>
            <div id="div2center">
                <div id="divMain2">
                    <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
                    <asp:Label ID="lblCounter" runat="server" Text="Counter"></asp:Label>
                </div>
            </div>
            <div id="div3right">
            </div>
        </form>
    </body>
    </html>
    
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    
    public partial class index2: System.Web.UI.Page
    
    
    
        protected void lblCounter_Load(Object sender, EventArgs e)
    
    
        {
    
        //checks to see if session("count") is empty if provides value to label lblCounter
    
    
    	  
        if (Session["count"] != null) {
    		lblCounter.Text = "Number Registrations saved: " + Session["count"].ToString();
    
    } else {
    		lblCounter.Text = "Number Registrations saved: 0";
    	}
    }
    
    
    


    • Edited by dcfun123456 Monday, October 10, 2016 9:03 PM
    Monday, October 10, 2016 9:00 PM

All replies

  • Have you tried to back up the project and add a new Web Form using the Wizard? It should create the necessary “.designer.cs” file. Check if it works, then move the <html> area to aspx file and the functions to .cs file. The .designer.cs file should be regenerated automatically. If you rename the page (which is better to do in Solution Explorer) or the class (which can be done using Refactor features), then make sure that CodeBehind and Inherits are correct, including the namespaces if necessary.

    Seems that it works better with .designer.cs file and CodeBehind instead of CodeFile.


    Tuesday, October 11, 2016 6:09 AM
  • no dice, I deleted all Visual studio files and reinstalled, still getting the same message that the definition of object is hidden, this happened after I did the update 3 to 2015. 

    for some reason it just will not recognize that their are controls on the page for C#, VB.NET works fine.

    Help Please - Any website I create that is C# has this issue what is going on?

    • Edited by dcfun123456 Saturday, October 15, 2016 3:17 AM
    Saturday, October 15, 2016 3:11 AM
  • Hi my friend,

    >>Any website I create that is C# has this issue what is going on?

    Hi dcfun123456,

    Thank you for your post.

    >> Any website I create that is C# has this issu

    If you have trouble about creating any new C# website application, You can try this to restore missing templates:

    Please open Windows Explorer, and navigate to  <Visual Studio Installation Path>\Common7\IDE (by default is C:\Program Files \Microsoft Visual Studio 14.0\Common7\IDE);

     1.Delete the ItemTemplatesCache, ProjectTemplatesCache folder;
     2.Open Visual Studio Command Prompt  under Start menu -> All Programs -> Microsoft Visual Studio 2015 -> Visual Studio Tools (run it with Administrator privilege: right-click the program -> Run as administrator);
    3.Run the devenv /InstallVSTemplates switch;
    4.Run the devenv /Setup switch

    Please refer to:

    https://msdn.microsoft.com/en-us/library/ms247116(v=vs.100).aspx

    >>Everything was working fine till I did update 3 to visual studios last week

    Have you checked if your VS 2015 Update 3 install well?

    If the re-install couldn't fix it, could you please tell us in which way you re-install VS ?

    To eliminate internet variables, I suggest that you download the ISO, verify the SHA-1 to ensure the ISO is not corrupt, then install locally.
    PS: To make sure whether your package is corrupted or not,
    please use FCIV.exe
    http://support.microsoft.com/kb/841290  to verify hash of the ISO.
    Any discrepancy would indicate that the file was corrupted. Here is a
    blog for how to use it, you can refer to it.

    VS 2015 iso files SHA-1 Values link:

    https://www.visualstudio.com/en-us/downloads/visual-studio-2015-iso-sha1-vs.aspx

    If the above still doesn't help, I need you installation log file to troubleshoot this issue,
    please use 
    http://aka.ms/vscollectto gather the installation logs. After using it, you will find vslogs.zip from %temp% folder. Please upload the file to  https://onedrive.live.com/and share the link here.

    Best Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.

    Click HERE to participate the survey.


    Tuesday, October 18, 2016 8:46 AM
    Moderator