0

How can i inherit the class, when i try to inherits it gives me an error.

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

public partial class expresion2 : System.Web.UI.Page
{
    public String nombre, email, telefono, contra, usuario;

    protected void Page_Load(object sender, EventArgs e)
    {
        nombre = txtNombre.Text;
        email = txtEmail.Text;
        telefono = txtTel.Text;
        contra = txtContra.Text;
        usuario = txtUser.Text;


    }
}

When i try inherit "expresion2" it gives me a compilation error on VS studio 2016

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

public partial class mostrar2 : expresion2
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
}

enter image description here

1 Answer 1

6

Your mostrar2 and expression2 classes are not defined in a namespace.

The correct definitions would be the below;

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

namespace myNamespace
{
    public partial class expresion2 : System.Web.UI.Page
    {
        public String nombre, email, telefono, contra, usuario;

        protected void Page_Load(object sender, EventArgs e)
        {
            nombre = txtNombre.Text;
            email = txtEmail.Text;
            telefono = txtTel.Text;
            contra = txtContra.Text;
            usuario = txtUser.Text;


        }
    }
}

And;

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

namespace myNamespace
{
    public partial class mostrar2 : expresion2
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
    }
}
Sign up to request clarification or add additional context in comments.

1 Comment

It doesn't work! still giving the same error, is there another way to inherit variables from expresion2 to mostra2?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.