Visual Studio 2015代码隐藏(codeFile)似乎不在关联的ASPX中定位控件(对象) [英] Visual Studio 2015 Code-Behind (codeFile) does not seem to be locating controls(objects) in associated ASPX

查看:72
本文介绍了Visual Studio 2015代码隐藏(codeFile)似乎不在关联的ASPX中定位控件(对象)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用两个页面在Visual Studio 2015中创建一个网站.

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

我有2个网页(index.aspx和index2.aspx),两个页面的顶部都有页面控件,它们的角度为CodeFile ="index.aspx.cs".和CodeFile =" index2.aspx.cs".

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".

还继承了index和index2.

also Inherits index and index2.

索引页面上有按钮,验证,texbox和标签,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.

第一选择列表-  wk4_site_cs

Fist select list -  wk4_site_cs

第二个-索引(通常是列出控件的位置,至少对于VB.NET而言)

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  

我看到了另一篇有关此的文章,但是那些解决方案从未奏效,并且适用于VS的较旧版本.我正在使用更新3的2015.

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";
	}
}


推荐答案

您是否尝试过备份项目并使用向导添加新的Web窗体?它应该创建必要的".designer.cs"文件.检查它是否有效,然后移动< html>区域到aspx文件,函数到.cs文件. .designer.cs文件应 自动重新生成.如果您重命名页面(最好在解决方案资源管理器"中完成)或类(可以使用重构"功能完成)重命名,则请确保 CodeBehind Inherits 是正确的,必要时包括名称空间.

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.

似乎它与.designer.cs文件和 CodeBehind 一起使用时效果更好 CodeFile .

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


这篇关于Visual Studio 2015代码隐藏(codeFile)似乎不在关联的ASPX中定位控件(对象)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆