tags:

views:

255

answers:

5

Dear All, I want to ask about session. Is it possible to create session from JavaScript? How ?

Thx, for ur response

+1  A: 

No

Javascript works on client side and you won't be able to set or destroy session which is created on server from javascript.

With the help of a server side language like C# you can achieve this.

rahul
+2  A: 

So, technically no. Sessions are server side and javascript runs on the client.

But, you can have your javascript send a request to the server that initiates a session. You'd still need some coding on the server, though (PHP, Java, etc.). Ex., it's fairly common practice to initiate a new session for a user when they log in (of note, they'll often already have a session, so you're really re-initializing).

Sam Bisbee
Er, but the JS to do this would have to have been returned by the server and therefore have created a session already.
annakata
Not necessarily. Ex., if the page with the JS was static HTML, then PHP (or whatever) wouldn't get a chance to initiate a session.
Sam Bisbee
A: 

to set the value of session you can user page method because it is not possible in js.

Abhisheks.net
A: 

I agree of course with others here. Although technically, you can control the client-side portion of the session state with javascript because javascript has control over the cookies where the client-side session information is stored. You cannot initiate a session with javascript, that has to be done by the server. But if the server uses some client-side state to determine if the next request will result in the creation of a session, you have control with javascript. For instance, perhaps setting a session id cookie and then talking to the server will cause it to create a session with that id for you. Depends on the server. A decent server should not do that. Also, once you have a session through whatever means, you can modify the client-side portion of session data if it is present and you know how to read it. However, a proper implementation of sessions just has a session id in a cookie on the client-side. If that's all the server in question uses, not much to edit there.

perrierism
A: 

Ok, Thx for the responses.

I Use PageMethod from Javascript to access c# method. C# method in static form. [WebMethod] public static void getHTMLTableValue() { // here I want to call My Dynamic HTMLTable Control(ex:tblA) // but i cannot fount tblA Control, how can I get my tblA ? }

Yayan

related questions