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

Sachin SinghRank #66 · 26.2K reputationPosted Dec 30, 2021, 12:52 AM EST
Shweta LodhaRank #31 · 39.8K reputationPosted Dec 29, 2021, 6:59 PM EST
{
ClientScript.RegisterStartupScript(this.GetType(), "", "alert('" + login.x + "');", true);
}
Valerie MeunierRank #1,527 · 1K reputationPosted Dec 30, 2021, 5:19 AM EST
Sachin SinghRank #66 · 26.2K reputationPosted Dec 30, 2021, 5:43 AM EST
Valerie MeunierRank #1,527 · 1K reputationPosted Dec 31, 2021, 10:12 AM EST
Rijwan AnsariRank #82 · 24.2K reputationPosted Jan 2, 2022, 12:05 PM EST