Handsome
Handsome

Reputation: 225

ASPNET: Make sure that the class defined in this code file matches the 'inherits' attribute

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();
    }
}
}

The code running fine until I wich to add namespace on top of the code then its throw me the error.

Compilation Error Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message:

ASPNET: Make sure that the class defined in this code file matches the 'inherits' attribute, and that it extends the correct base class (e.g. Page or UserControl).

Source Error: Line 19: public partial class _Default

Upvotes: 6

Views: 20899

Answers (2)

Rahul Singh
Rahul Singh

Reputation: 21825

The Page Directive in the .aspx page consists of two important attributes:-

CodeBehind - Specifies the code behind file associated with Mark-up (.aspx) page.

Inherits - Now since the code behind class specified by CodeBehind attribute is a C# class and we know inside a Namespace we have have multiple classes, So with Inherits attribute you need to specify the exact fully qualified class name associated with your markup page.

So your Page directive should look like this:-

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

Upvotes: 3

Mairaj Ahmad
Mairaj Ahmad

Reputation: 14624

You need to add namespace before class name in aspx page in inherits attribute.

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

Upvotes: 13

Related Questions