【问题标题】:Controls of .aspx pages are not accessible in .aspx.cs page.aspx 页面的控件在 .aspx.cs 页面中不可访问
【发布时间】:2014-06-06 13:54:44
【问题描述】:

我正在将我现有的网站项目转换为网络应用程序,因为我创建了一个新的网络应用程序并将网站项目的整个源代码复制到网络应用程序项目中。但是现在的问题是当我在编译项目时,.aspx 页面控件在 .aspx.cs 页面中是不可访问的。我在 VS 2012 中使用目标框架 3.5 执行此操作。

这里是代码sn-p

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>

源代码

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

【问题讨论】:

  • 你能告诉我们相应的代码吗?
  • 嗨@rhughes 感谢您的快速回复。我已经编辑了我的问题并添加了我的代码 sn-p。我不想再次更改我的项目类型网站。

标签: asp.net c#-3.0 code-behind


【解决方案1】:

在将应用程序从网站转换为 Web 应用程序时,您需要将 CodeFile 更改为 CodeBehind。

CodeBehind="View_Deal_Rights.aspx.cs"

一旦你改变然后构建,你就可以访问了。

有关更多详细信息,请参阅以下问题。

CodeFile vs CodeBehind

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-31
    • 2012-06-04
    • 1970-01-01
    • 2016-01-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多