Valerie Meunier

Valerie Meunier

  • NA
  • 693
  • 82.8k

variable not recognized in same namespace

Dec 29 2021 6:03 PM

Hi
If the access modifier of a variable is internal (or public), it will be reachable from everywhere in the namespace.
In this website app, i define a public variable in class Login. I know there are other ways to pass variable from page to page (session, viewstate ..) but i wonder why the variable is not recognized in the other class Textbox (which is in the same namespace).

Thanks.
V.
namespace test 
{
    public partial class Login : System.Web.UI.Page
    {
        public int x = 5;
    ...
--------------
namespace test 
{
    public partial class Textbox : System.Web.UI.Page
    {
    ...

 protected void Page_Load(object sender, EventArgs e)
        {
        ClientScript.RegisterStartupScript(this.GetType(), "", "alert('" + x + "');", true);
        }


Answers (6)