0

我在 VS2008 中将较旧的 Web 应用程序转换为适当的 Web 应用程序,同时使用命名空间更明确。

但是,自从这样做以来,我遇到了一个问题,即我的基本页面中的某些字段对页面后面的代码不可见。最大的问题当然是母版页。

我已经复制了母版页并重新键入了所有手动重新创建设计器文件的内容,但仍然在后面的两个代码上我得到了同样的错误:

错误 1 ​​当前上下文中不存在名称 'lb_Version' C:\SourceControl\JFA Admin Portal\Website\JFA_Admin\MasterPageSimple.master.cs 26 13 JFA_Admin

母版页如下:

基页:

<%@ Master Language="C#" AutoEventWireup="true" CodeFile="MasterPageSimple.master.cs" Inherits="JFA_Admin.MasterPageSimple" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>


<!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 runat="server">
        <title>Welcome to JFA Admin</title>
        <meta name="Author" content="Marcus Culver"/>
        <link href="Default.css" rel="stylesheet" type="text/css" /> 
    </head>
    <body>
        <div id="MasterPageSimpleWrapper" class="wrapper">
            <form id="form1" runat="server">
                <div id="MasterPageSimpleHeader" >
                    <cc1:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
                    </cc1:ToolkitScriptManager> 
                    <br /> <br /> 
                    <div style="text-align:center">
                        <asp:Image ID="Image1" runat="server" ImageUrl="Images/JFA_Admin.png" CssClass="" />
                    </div>
                    <br /> <br /> <br /> <br /> <br /> <br />
                    <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
                    </asp:ContentPlaceHolder>
                    <br />
                    <br />
                    <br />
                    <asp:Label ID="lb_Version" runat="server"></asp:Label>
                </div>
            </form> 
        </div>
    </body>
</html>

代码背后:

using System;
using System.IO;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;

namespace JFA_Admin
{
    public partial class MasterPageSimple : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Page_Init(object sender, EventArgs e)
        {
            lb_Version.Text = ConfigurationManager.AppSettings["Env"] + ": " + ConfigurationManager.AppSettings["Ver"];
        }
    }
}
4

1 回答 1

0

结果我添加了一个与命名空间同名的页面,这在尝试引用命名空间时导致了冲突。

重命名页面并将标签移回 Page_Load (根据 Sonar 的评论),一切似乎都在工作。即使有CC!脚本管理器的标签。

基页:

<%@ Master Language="C#" AutoEventWireup="True" Inherits="JFA_Admin.MasterPageSimple" Codebehind="MasterPageSimple.master.cs" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>

<!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 runat="server">
        <title>Welcome to JFA Admin</title>
        <meta name="Author" content="Marcus Culver"/>
        <link href="Default.css" rel="stylesheet" type="text/css" /> 
    </head>
    <body>
        <div id="MasterPageSimpleWrapper" class="wrapper">
            <form id="form1" runat="server">
                <cc1:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server" />
                <div id="MasterPageSimpleHeader" >
                    <br /> <br /> 
                    <div style="text-align:center">
                        <asp:Image ID="Image1" runat="server" ImageUrl="Images/JFA_Admin.png" CssClass="" />
                    </div>
                    <br /> <br /> <br /> <br /> <br /> <br />
                    <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
                    </asp:ContentPlaceHolder>
                    <br />
                    <br />
                    <br />
                    <asp:Label ID="lb_Version" runat="server"></asp:Label>
                </div>
            </form> 
        </div>
    </body>
</html>

代码背后:

using System;
using System.IO;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;

namespace JFA_Admin
{
    public partial class MasterPageSimple : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            lb_Version.Text = ConfigurationManager.AppSettings["Env"] + ": " + ConfigurationManager.AppSettings["Ver"];
        }
    }
}

谢谢声纳 Gönül

于 2013-11-01T12:58:50.513 回答