ASPNET:确保此代码文件中定义的类与'inherits'属性

时间:2015-04-30 03:56:06

标签: c# asp.net

namespace ASPMultilingual { 
public partial class _Default : System.Web.UI.Page
{
    ResourceManager rm;
    CultureInfo ci;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["Lang"] == null) { 
            Session["Lang"] ="en-US";
        }

        if (!IsPostBack)
        {
            LoadString();

        }

    }

    private void LoadString(){

        Thread.CurrentThread.CurrentCulture = new CultureInfo(Session["Lang"].ToString());
        //rm = new ResourceManager("ASPMultilingual.App_GlobalResources.Lang", Assembly.GetExecutingAssembly());
        ResourceManager rm = new ResourceManager("ASPMultilingual.Lang", System.Reflection.Assembly.Load("ASPMultilingual"));
        ci = Thread.CurrentThread.CurrentCulture;


        btnLogIn.Text = rm.GetString("Login", ci);
    }

    protected void btnLogIn_Click(object sender, EventArgs e)
    {
        string ID = Request.Form["txtID"];
        String password = Request.Form["txtPassword"];
        string strConString = ConfigurationManager.ConnectionStrings["SOConnectionString"].ConnectionString;
        OleDbConnection conn = new OleDbConnection(strConString);
        OleDbCommand cmd = new OleDbCommand("SELECT * FROM USERMASTER", conn);

        try
        {

            conn.Open();
            OleDbDataReader dr;

            dr = cmd.ExecuteReader();
            while (dr.Read()) {
                string testposition = dr["UserPosition"].ToString();
                string dataID = dr["UserId"].ToString();
                string dataPass = dr["UserPwd"].ToString();
                if (dataPass == txtPassword.Text && dataID == txtID.Text)
                {
                    Session["User_Position"] = testposition;
                    Response.Redirect("Default2.aspx");
                }
                else {

                    lblError.Text = "Invalid account! Please Enter again!";
            }

            }


        }
        catch (Exception ex)
        {
            txtID.Text = "ex";
            lblError.Text = ex.ToString();


        }
        finally
        {
            conn.Close();
            conn.Dispose();
        }


        //Response.Redirect("Default2.aspx");
        //ClientScript.RegisterStartupScript(this.GetType(), "yourMessage", "alert('" + ID + " " + password + "');", true);

    }

    protected void ddLang_SelectedIndexChanged(object sender, EventArgs e)
    {
        Session["Lang"] = ddLang.SelectedValue;
        LoadString();
    }
}
}

代码运行正常,直到我在代码顶部添加命名空间然后它抛出错误。

编译错误 描述:编译服务此请求所需的资源时发生错误。请查看以下特定错误详细信息并适当修改源代码。

编译器错误消息:

  

ASPNET:确保此代码文件中定义的类与   'inherits'属性,并且它扩展了正确的基类(例如   Page或UserControl)。

来源错误: 第19行:公共部分类_Default

2 个答案:

答案 0 :(得分:7)

您需要在inherits属性中的aspx页面中的类名之前添加命名空间。

<%@ Page Title="Some Title" Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="ASPMultilingual._Default" %>

答案 1 :(得分:0)

.aspx页面中的CodeBehind包含两个重要属性: -

CodeBehind - 指定与标记(.aspx)页面关联的代码隐藏文件。

继承 - 现在由于<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="ASPMultilingual._Default" %> 属性指定的代码隐藏类是C#类,我们知道在命名空间内我们有多个类,所以使用Inherits属性需要指定与标记页面关联的完全限定类名。

所以你的Page指令应如下所示: -

import java.util.Scanner;

public class Test {

public static void main(String[] arg){
    try{
        Scanner in = new Scanner(System.in); 
        System.out.printf("Enter first Value:  ");
        double a = in.nextDouble();

        System.out.printf("Enter second Value:  ");
        double b = in.nextDouble();

        System.out.println("Division result: "+a/b);
    } catch(Exception e){
        e.printStackTrace();
    }
  }
}