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);
}
Rijwan AnsariPosted Jan 2, 2022, 5:05 PM
Valerie MeunierPosted Dec 31, 2021, 3:12 PM
Sachin SinghPosted Dec 30, 2021, 10:43 AM
Valerie MeunierPosted Dec 30, 2021, 10:19 AM
Sachin SinghPosted Dec 30, 2021, 5:52 AM
Shweta LodhaPosted Dec 29, 2021, 11:59 PM
{
ClientScript.RegisterStartupScript(this.GetType(), "", "alert('" + login.x + "');", true);
}