【问题标题】:Web site to Web App: aspx.cs can't see controls in .aspx网站到 Web 应用程序:aspx.cs 看不到 .aspx 中的控件
【发布时间】:2013-06-01 19:26:13
【问题描述】:

我正在尝试将网站项目转换为 Web 应用程序,但遇到了一些问题,即 .aspx.cs 文件在 .aspx 中看不到任何控件。我尝试删除 .designer.cs 文件并再次转换为 Web 应用程序,但这并没有解决我的问题。如果我将 .designer.cs 文件的命名空间更改为“SoftwareCheckout”(与我的 .aspx.cs 相同的命名空间),.aspx.cs 可以很好地看到 .aspx 中的控件,但由于 .designer.cs是自动生成的,我将在它重新生成后立即对其进行任何更改。这让我相信这是我的命名空间的问题,但我不是 100% 确定。

这是我的 .aspx 的第一行,名为 StuCheckout.aspx:

<%@ Page Language="C#" AutoEventWireup="True" Inherits="StuCheckout" Codebehind="StuCheckout.aspx.cs" %>

这是我的 .aspx.cs 的前几行,名为 StuCheckout.aspx.cs(例如,无法访问 lblUser 和 lblTime)

namespace SoftwareCheckout
{
    public partial class StuCheckout : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                lblUser.Text = CurrentUser.getUsername();
                lblTime.Text = CurrentUser.getDate();
                setLocalRestrictions();
                if (!(lblErrorText.Text == String.Empty))
                    lblErrorText.Visible = true;

我的 .designer.cs 看起来像这样:

 //------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated. 
// </auto-generated>
//------------------------------------------------------------------------------



public partial class StuCheckout {

/// <summary>
/// Head1 control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.HtmlControls.HtmlHead Head1;

还有其他人遇到过这个问题吗?我的想法已经用完了,非常感谢任何帮助!

【问题讨论】:

    标签: asp.net web-site-project web-application-project


    【解决方案1】:

    尝试将命名空间添加到前端 (.aspx) 页面上的继承和类声明; @Page 指令有一个可以使用的 Inherits 或 Class 属性。 请参阅此处的“其他转换选项”部分: http://msdn.microsoft.com/en-us/library/aa983476(v=vs.100).aspx

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-15
      • 1970-01-01
      相关资源
      最近更新 更多