Why not javascript session value getting into code behind into asp.net

Posted by Cpatil1000 under ASP.NET on 4/25/2016 | Points: 10 | Views : 204 | Status : [Member] | Replies : 1
I am trying getting value of session value from javascript. First time it not getting
but if I try second time it is getting becuase of first time session value is getting null
and second time value is storing which is i am trying of password. I can use hidden value
because of software auditing. I tyring getting value from 'Session["KEY"]' which i have
used in javascript. and i am using master page. so my script in master page

<asp:ToolkitScriptManager ID="tsmMains" runat="server" EnablePageMethods="true">

<script type="text/javascript">
function EncryptPassword() {

var key = '<%= Session["KEY"] %>';

if (!document.getElementById('<%=tbPassword.ClientID %>').value == '') {

var password = document.getElementById('<%=tbPassword.ClientID %>').value;
var encrypted = CryptoJS.TripleDES.encrypt(password, key);

document.getElementById('<%=tbPassword.ClientID %>').value = encrypted.toString();



protected void Page_Load(object sender, EventArgs e)
if (!Page.IsPostBack)
this.bLogin.Attributes.Add("onClick", "EncryptPassword()");

public static string SetDownloadPath(string strpath)
//Page objp;

//objp = new Page();

//objp.Session["KEY"] = strpath;

nMess = strpath;

return strpath;


Posted by: Bhuvanesh6 on: 7/31/2016 [Member] Starter | Points: 25

Usually session are maintained on the server side components and the Javascript data which are maintained are on the client side.

When you are trying to use the client side components on the server side, it need to send the data from client to server say for example like hidden field of form hold a value and form collection is sent to the server.

You are trying to use the client side values directly with the server which is not possible to access directly.


Cpatil1000, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response