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 : 1380 | Status : [Member] | Replies : 1
Hi,
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">
</asp:ToolkitScriptManager>


<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();

InitializeRequest(password);
}
}
</script>



cs.code
=========

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

[WebMethod]
public static string SetDownloadPath(string strpath)
{
//Page objp;

//objp = new Page();

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

nMess = strpath;

return strpath;
}





Responses

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

Up
0
Down
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.

Bhuvan

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

Login to post response