简体   繁体   English

C#找不到类型或名称空间名称

[英]C# The type or namespace name could not be found

I have a problem that has been driving me nuts. 我有一个困扰我的问题。

I have 2 ASPX pages in which the parent use Server.Transfer() function. 我有2个ASPX页面,其中父级使用Server.Transfer()函数。 The parent is called Submit.aspx whereas child is called Review.aspx 父级称为Submit.aspx,而子级称为Review.aspx

In Submit.aspx.cs, I have: 在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; } }
}

Whereas on the Review.aspx.cs, I have: 而在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;
        }
    }
}

The problem is when I declare " Contacts_Submit prevpage = PreviousPage as Contacts_Submit ". 问题是当我声明“ Contacts_Submit prevpage = PreviousPage as Contacts_Submit ”时。 The system is giving me an error that says "The type or namespace name 'Contacts_Submit' could not be found (are you missing a using directive or an assembly reference?)". 系统给我一个错误,提示“找不到类型或名称空间名称'Contacts_Submit'(您是否缺少using指令或程序集引用?)”。

I am a beginner in both ASP.NET and C#, can anyone help me with this? 我是ASP.NET和C#的初学者,有人可以帮助我吗? Thank you SOOO MUCH. 谢谢您。

I think you just want 我想你只是想要

Contacts_Submit prevpage = PreviousPage as Contacts_Submit;

instead of 代替

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

Contacts_Submit is type of Page and not in any way related to Dataset , so your cast is invalid. Contacts_Submit是Page类型, 与Dataset没有任何关系 ,因此您的类型转换无效。 remove that and it should be fine 删除它,应该没问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM