1

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. But now the problem is when I am compiling the project .aspx page controls are not accessible in .aspx.cs page. I am doing this in VS 2012 with target framework 3.5.

Here is the code snippet

HTML Source

<%@ 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
        }
    }
}
Adesh Arote
  • 105
  • 2
  • 10

1 Answers1

1

You need to change CodeFile to CodeBehind as you converted your application from web site to web application.

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

Community
  • 1
  • 1
Jalpesh Vadgama
  • 13,653
  • 19
  • 72
  • 94