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

发布于 2024-10-17 08:42:11 字数 2614 浏览 1 评论 0原文

我有一个问题一直让我发疯。

我有 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”时作为Contacts_Submit”。系统给我一个错误,显示“找不到类型或命名空间名称‘Contacts_Submit’(您是否缺少 using 指令或程序集引用?)”。

我是 ASP.NET 和 C# 的初学者,有人可以帮助我吗?非常感谢。

I have a problem that has been driving me nuts.

I have 2 ASPX pages in which the parent use Server.Transfer() function. The parent is called Submit.aspx whereas child is called Review.aspx

In Submit.aspx.cs, I have:

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:

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". 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?)".

I am a beginner in both ASP.NET and C#, can anyone help me with this? Thank you SOOO MUCH.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

横笛休吹塞上声 2024-10-24 08:42:11

我想你只是想要

Contacts_Submit prevpage = PreviousPage as Contacts_Submit;

而不是

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

I think you just want

Contacts_Submit prevpage = PreviousPage as Contacts_Submit;

instead of

Contacts_Submit prevpage = PreviousPage as System.Data.DataSet Contacts_Submit;
給妳壹絲溫柔 2024-10-24 08:42:11

Contacts_Submit 是页面类型,与数据集没有任何关系,因此您的转换无效。
删除它应该没问题

Contacts_Submit is type of Page and not in any way related to Dataset, so your cast is invalid.
remove that and it should be fine

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文