对象在.cs文件中不可用

时间:2014-09-24 07:29:03

标签: c# asp.net

我正在制作一个html模板,我已将其转换为.aspx格式...我已将所有html代码复制到.aspx,现在当我在设计或.aspx中插入任何像文本框,按钮等的asp项目时文件并双击它,但它不会交换到.cs文件,如果我去.cs文件并手动创建方法仍然没有响应。当我写对象名称,例如TextBox1.text时,TextBox1用红色加下划线,就像对象不可用一样。 这个问题的本质和灵魂是什么?

这是aspx代码:

    <body class="home page page-id-53 page-template page-template-page-properties-grid-php  header-light color-blue pattern-none layout-wide ">

    <div id="wrapper-outer">
        <div id="wrapper">
            <div id="wrapper-inner">
                <div class="header-top-wrapper">
                    <div class="header-top">
                            <div class="breadcrumb-wrapper">
            <div class="container">
                <div class="row">
                    <div class="span12">
                                                                    <div class="breadcrumb pull-left">
                                                                <!-- Breadcrumb NavXT 5.1.1 -->
    Realia
                                                        </div><!-- /.breadcrumb -->

                                                                    <div class="account pull-right">
                                                                <div class="menu-anonymous-container"><ul id="menu-anonymous" class="nav nav-pills"><li id="menu-item-124" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-124"><a href="login/index.html">Login</a></li>
    <li><asp:HyperLink ID="Resgister" CssClass="menu-item menu-item-type-post_type menu-item-object-page menu-item-123" NavigateUrl="~/register.aspx" runat="server">Register</asp:HyperLink></li>

    </ul></div>

                            </div>
                                        </div><!-- /.span12 -->
                </div><!-- /.row -->
            </div><!-- /.container -->
        </div><!-- /.breadcrumb-wrapper -->

                        <!-- HEADER -->
                        <div id="header-wrapper">
                            <div id="header">
                                <div id="header-inner">
                                    <div class="container">
                                        <div class="navbar">
                                            <div class="navbar-inner">
                                                <div class="row">
                                                    <div class="logo-wrapper span4">
                                                        <a href="#nav" id="btn-nav">Toggle navigation</a>

                                                                                                            <div class="logo">
                                                                                                                        <a href="index.html" title="Home">
                                                                                                                                                                                        <img src="wp-content/themes/realia/assets/img/logo.png" alt="Home">
                                                                                                                        </a>
                                                        </div><!-- /.logo -->

  <asp:Button ID="Button1" runat="server" Text="Button" /> 
                                                                                                                                                                                                                                <div class="site-name">
                                                                    <a href="index.html" title="Home" class="brand">
                                                                    </a>
                                                                </div><!-- /.site-name -->

                                                                                                                                                                                                                                <div class="site-slogan">
                                                                    <span>Real estate & Rental <br>made easy</span>
                                                                </div><!-- /.site-slogan -->
                                                                                                                                                                </div><!-- /.logo-wrapper -->

                                                                                                        <div class="info">
                                                                                                                                                                                <div class="site-email">
                                                                    <a href="mailto:info@byaviators.com">
                                                                        info@byaviators.com
                                                                    </a>
                                                                </div><!-- /.site-email -->

                                                                                                                                                                                <div class="site-phone">
                                                                    <span>333-444-555</span>
                                                                </div><!-- /.site-phone -->
                                                                                                                </div><!-- /.info -->


                                                        <a class="btn btn-primary btn-large list-your-property arrow-right"
                                                            href="my-properties/index.html">
                                                            List your property
                                                        </a>
                                                                                                </div><!-- /.row -->
                                            </div><!-- /.navbar-inner -->
                                        </div><!-- /.navbar -->
                                    </div><!-- /.container -->
                                </div><!-- /#header-inner -->
                            </div><!-- /#header -->
                        </div><!-- /#header-wrapper -->
                    </div><!-- /.top -->
                </div><!-- /.top-wrapper -->

                <!-- NAVIGATION -->
                <div id="navigation">
                    <div class="container">
                        <div class="navigation-wrapper">
                            <div class="navigation clearfix-normal">
                                <div class="menu-main-container">
                                    <ul id="menu-main" class="nav">
                                        <li id="menu-item-355" class="menu-item menu-item-type-custom menu-item-object-custom current-menu-ancestor current-menu-parent menu-item-has-children menu-item-355">
                                            <asp:HyperLink ID="NavHome" NavigateUrl="~/Index.aspx" runat="server">Home</asp:HyperLink>
                                          </li>
                                       <li id="menu-item-78" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-has-children menuparent menu-item-78"><asp:HyperLink ID="NavSale" NavigateUrl="~/properties.aspx" runat="server">Sale</asp:HyperLink>

                                        <ul class="sub-menu">
                                                <li id="menu-item-52" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-52"><a href="blog/index.html">Apartment</a></li>
                                                <li id="menu-item-148" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-148"><a href="right-sidebar/index.html">Commercial</a></li>
                                                <li id="menu-item-137" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-137"><a href="login/index.html">Residential</a></li>
                                                <li id="menu-item-149" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-149"><a href="left-sidebar/index.html">Land</a></li>
                                                <li id="menu-item-136" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-136"><a href="register/index.html">All</a></li>
                                           </ul>

                                      </li>
                                      <li id="menu-item-78" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-has-children menuparent menu-item-78"><asp:HyperLink ID="NavPurchase" NavigateUrl="~/properties.aspx" runat="server">Purchase</asp:HyperLink>

                                        <ul class="sub-menu">
                                                <li id="menu-item-52" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-52"><a href="blog/index.html">Apartment</a></li>
                                                <li id="menu-item-148" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-148"><a href="right-sidebar/index.html">Commercial</a></li>
                                                <li id="menu-item-137" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-137"><a href="login/index.html">Residential</a></li>
                                                <li id="menu-item-149" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-149"><a href="left-sidebar/index.html">Land</a></li>
                                                <li id="menu-item-136" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-136"><a href="register/index.html">All</a></li>
                                           </ul>

                                      </li>
                                      <li id="menu-item-56" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-56"><asp:HyperLink ID="NavAgents" NavigateUrl="~/agents.aspx" runat="server">Agents</asp:HyperLink>
                                      </li>
                                      <li id="menu-item-56" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-56">
                                            <a href="agents/index.html">Construction</a>
                                      </li>
                                      <li id="menu-item-63" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-63"><asp:HyperLink ID="NavContact" NavigateUrl="~/contact-us.aspx" runat="server">Contact us</asp:HyperLink></li>
                                </ul>

                                </div>

                                <div id="icl_lang_sel_widget" class="widget icl_languages_selector"><div id="lang_sel"  >
        <ul>
            <li><a href="#" class="lang_sel_sel icl-en">

                <img  class="iclflag" src="wp-content/plugins/sitepress-multilingual-cms/res/flags/en.png" alt="en"  title="English" />                                
                &nbsp;English</a>                                    
                <ul>
                                                    <li class="icl-fr">          
                        <a rel="alternate" hreflang="fr" href="fr/index.html">

                        <img  class="iclflag" src="wp-content/plugins/sitepress-multilingual-cms/res/flags/fr.png" alt="fr" title="Français" />&nbsp;                    
                                            Français                    </a>
                    </li>
                                    <li class="icl-de">          
                        <a rel="alternate" hreflang="de" href="de/index.html">

                        <img  class="iclflag" src="wp-content/plugins/sitepress-multilingual-cms/res/flags/de.png" alt="de" title="Deutsch" />&nbsp;                    
                                            Deutsch                    </a>
                    </li>
                                </ul>            

                        </li>
        </ul>    
    </div>
    </div>                                                                                                                </div><!-- /.navigation -->
                        </div><!-- /.navigation-wrapper -->
                    </div><!-- /.container -->
                </div><!-- /.navigation -->


        <!-- /.map -->
    </div><!-- /.map-wrapper -->        </div><!-- /.top-inner -->

            </div>


    </body>

c#代码:

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)
    {

    }
}

2 个答案:

答案 0 :(得分:2)

从您的代码中我看不到ASPX文件中的标题。它应该是这样的:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Index.aspx.cs" Inherits="Index" %>

这将ASPX文件和CS文件一起映射到一个(因此在代码声明后面的partial部分)。

答案 1 :(得分:0)

您很可能没有设置runat="server"标记。没有它,CodeBehind根本不知道控件。