开发者

Asp.Net Change a value from another page

开发者 https://www.devze.com 2023-02-24 10:49 出处:网络
Hi I have 2 webpage in my asp.net project. I 开发者_JAVA技巧defined a int value in second page. i want to change int value from first page. How can I make this? You can\'t change the variable directly

Hi I have 2 webpage in my asp.net project. I 开发者_JAVA技巧defined a int value in second page. i want to change int value from first page. How can I make this?


You can't change the variable directly. But you can use Session to achieve this.

In Page 1

Session["session-name"] = "5";

In Page 2

      if (Session["session-name"] != null) // check the session if it is exist
            {
                int a;
                try
                {
                    a = int.Parse(Session["session-name"].ToString());
                }
                catch
                {
                    a = 0; // you can set null too. Whatever you want
                }
            }


You likely want to use Session Variables. You can start learning here.

0

精彩评论

暂无评论...
验证码 换一张
取 消