Asp.Net Session Variable in JavaScript
-
Hello Everybody, I have an application where I have to store some values in Session variables. And later on I need to use those values in a JavaScript function. Can anyone tell me how to access Session values in JavaScript or some better approach to this situation.. HappyCoding
-
Hello Everybody, I have an application where I have to store some values in Session variables. And later on I need to use those values in a JavaScript function. Can anyone tell me how to access Session values in JavaScript or some better approach to this situation.. HappyCoding
var sessionValue = <% Session["value"].ToString() %>
All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia My Website | Ask smart questions
-
var sessionValue = <% Session["value"].ToString() %>
All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia My Website | Ask smart questions
Hello, Thanks Buddy...but its gives me the value undefined... my code is as below. (In JavaScript): var ImageUrl = <% Session["ImageUrl"].ToString(); %> (In ASPX file): HttpContext.Current.Session["ImageUrl"] = "image" + "/" + "it-cover.jpg"; and In case of HiddenField how to do it? HappyCoding
A key to every Solution
-
Hello Everybody, I have an application where I have to store some values in Session variables. And later on I need to use those values in a JavaScript function. Can anyone tell me how to access Session values in JavaScript or some better approach to this situation.. HappyCoding
It's impossible to access session variables from Javascript. The session variables never leaves the server. If you want to use the value from a session varible, you have to copy the value from the session variable and put it in the generated html code, for example by outputting Javascript code that creates a variable that contains the value from the session variable, as Navaneeth suggested.
Despite everything, the person most likely to be fooling you next is yourself.
-
Hello, Thanks Buddy...but its gives me the value undefined... my code is as below. (In JavaScript): var ImageUrl = <% Session["ImageUrl"].ToString(); %> (In ASPX file): HttpContext.Current.Session["ImageUrl"] = "image" + "/" + "it-cover.jpg"; and In case of HiddenField how to do it? HappyCoding
A key to every Solution
You need a single quotation (') around it. Try this
'<% Session["ImageUrl"].ToString(); %>';
All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia My Website | Ask smart questions