Is it possible to set localStorage or Session variable in asp.net page and read it in javascript on the other page?

后端 未结 5 1336
囚心锁ツ
囚心锁ツ 2020-12-19 07:45

As in question. Is it possible to set variable in asp.net page in localStorage and retrieve it on the other page?

How to set localStorage variable in asp.net. Is it

5条回答
  •  甜味超标
    2020-12-19 08:14

    Old post yes, but knowledge is always good.

    You can set the local or session storage from asp.net (indirectly). Since we can set up javascript code in asp.net and insert into the client side, there's no difference with the session or local storage.

    Try this from server side

    string script = string.Format("sessionStorage.userId= '{0}';", "12345");
    ClientScript.RegisterClientScriptBlock(this.GetType(), "key", script, true);
    

    That will set the session (you could do local) storage variable to the value 12345.

提交回复
热议问题