【问题标题】:C# The type or namespace name could not be foundC# 找不到类型或命名空间名称
【发布时间】:2011-06-28 02:20:58
【问题描述】:

我有一个问题一直让我抓狂。

我有 2 个 ASPX 页面,其中父级使用 Server.Transfer() 函数。父级称为 Submit.aspx,而子级称为 Review.aspx

在 Submit.aspx.cs 中,我有:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Contacts_Submit : BasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Review_Click(object sender, EventArgs e)
    {
        Server.Transfer("Review.aspx", true);
    }

    /* 
     * Sequence of functions that will server as a Get functionality that will
     * return the text inside each textbox.
     * These information will be used by "Review.aspx" to validate the
     * information given by the user before final submission takes place.
     */
    public string GetFirstName { get { return FirstName.Text; } }
    public string GetLastName { get { return LastName.Text; } }
    public string GetAddress { get { return Address.Text; } }
    public string GetCountry { get { return Country.SelectedValue; } }
    public string GetProvince { get { return Province.SelectedValue; } }
    public string GetCity { get { return City.Text; } }
    public string GetZipCode { get { return ZipCode.Text; } }
    public string GetWorkPhone { get { return WorkPhone.Text; } }
    public string GetMobilePhone { get { return MobilePhone.Text; } }
    public string GetFax { get { return Fax.Text; } }
    public string GetEmail { get { return Email.Text; } }
    public string GetCompany { get { return Company.Text; } }
    public string GetWebsite { get { return Website.Text; } }
    public string GetRelationship { get { return Relationship.SelectedValue; } }
}

而在 Review.aspx.cs 中,我有:

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

public partial class Contacts_Review : BasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if(PreviousPage != null)
        {
            Contacts_Submit prevpage = PreviousPage as Contacts_Submit;
            //FirstName.Text = PreviousPage.GetFirstName;
        }
    }
}

问题是当我声明“Contacts_Submit prevpage = PreviousPage as Contacts_Submit”时。系统提示我“找不到类型或命名空间名称‘Contacts_Submit’(您是否缺少 using 指令或程序集引用?)”。

我是 ASP.NET 和 C# 的初学者,谁能帮我解决这个问题?非常感谢。

【问题讨论】:

    标签: c# namespaces types .net-assembly directive


    【解决方案1】:

    我想你只是想要

    Contacts_Submit prevpage = PreviousPage as Contacts_Submit;
    

    而不是

    Contacts_Submit prevpage = PreviousPage as System.Data.DataSet Contacts_Submit;
    

    【讨论】:

      【解决方案2】:

      Contacts_Submit 是 Page 类型,与数据集没有任何关系,因此您的演员表无效。 删除它应该没问题

      【讨论】:

      • 抱歉没有更新代码。实际上,我确实使用了 System.Data 和没有它的两种方式。但它仍然不起作用。这真是令人困惑
      猜你喜欢
      • 2013-03-25
      • 2021-08-19
      • 1970-01-01
      • 2017-07-12
      • 2011-05-13
      • 2011-02-24
      • 2012-06-19
      • 2017-11-29
      相关资源
      最近更新 更多