简体   繁体   English

.aspx页的控件无法在.aspx.cs页中访问

[英]Controls of .aspx pages are not accessible in .aspx.cs page

I am converting my existing web site project to web application for that I have created a new web application and the copy the entire source code of web site project in web application project. 我正在将现有的网站项目转换为Web应用程序,因为我已经创建了一个新的Web应用程序,并将网站项目的整个源代码复制到Web应用程序项目中。 But now the problem is when I am compiling the project .aspx page controls are not accessible in .aspx.cs page. 但是现在的问题是,当我编译项目时,.aspx.cs页中无法访问.aspx页控件。 I am doing this in VS 2012 with target framework 3.5. 我正在使用目标框架3.5在VS 2012中执行此操作。

Here is the code snippet 这是代码片段

HTML Source HTML来源

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="View_Deal_Rights.aspx.cs" Inherits="Modules_View_Deal_Rights" 
    EnableEventValidation="false" ValidateRequest="false" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>
        <%=ConfigurationManager.AppSettings["SystemName"]%></title>
</head>
<body leftmargin="0" topmargin="10" marginwidth="0" marginheight="0" rightmargin="0"
    bottommargin="0">
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server" AsyncPostBackTimeout="0">
    </asp:ScriptManager>
    <asp:Label ID="lblok" runat="server"></asp:Label>
    <asp:Button ID="btnSave" runat="server" CssClass="button" Text="Save Deal" ValidationGroup="LastSave"/>
</form>
</body>
</html>

Code Behind Source 源代码背后

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using UTOFrameWork.FrameworkClasses;
using System.Collections;
using System.Data;
using System.Web.UI.HtmlControls;
using System.Text;

public partial class Modules_View_Deal_Rights : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
             btnSave.         // Here Button save is not accessable
             lblok.         // Here lblok is not accessable
        }
    }
}

You need to change CodeFile to CodeBehind as you converted your application from web site to web application. 在将应用程序从网站转换为Web应用程序时,需要将CodeFile更改为CodeBehind。

CodeBehind="View_Deal_Rights.aspx.cs"

Once you change then build and you will be able to access. 一旦更改,然后进行构建,便可以访问。

For more details see following question. 有关更多详细信息,请参见以下问题。

CodeFile vs CodeBehind CodeFile与CodeBehind

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM