Is there any appropriate method to clear a server side session on client side.
I use java script to clear a session, but when ever a page is redirected then server side session value will clear, even when the click event in not fire here is a java script code which I call on ONCLICK of LI
<script type="text/javascript">
function Clear_() {
'<%=Session["UID"]=""%>';// only this line executes when ever the page is redirected.
alert('ok');
}
</script>
The reason why this happens is while page is being parsed, it always looks for the server side tags and execute it first. Its same as parsing server side control. So even if you have written the code, to fire on click event of any button, the code would execute every time its loaded.
Even if you try to comment the code in server tag, the code would be executed.
The answer to your problem is NO. The sessions are stored as server side, then how could you clear it clide side. You have to make AJAX request to server and clear the session on server
UPDATE 2
Its same as the aspx page is parsed for server control. These server tags need to be processed while the request is at server and then evaluated the value. For example, if you want some value in javascript to be populated from some session value on the server.
So when the page is parsed, the value inside server tags are evaluated and replaced with their actual value(For control, its replaced with html). So in the final output, that is sent to client, the following markup would be sent
You could verify by looking in the “View Source” from the browser.