Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Actually i in my functionality i want to set the session value in javascript....i studied so many blogs about this. in that blogs said we can access but we can not assign. but in two blogs they said we can assign also but it is not working here below is the links where they said we can assign


VB
http://stackoverflow.com/questions/15519454/how-can-i-access-session-variables-and-set-them-in-javascript

http://shekharshetemcts.wordpress.com/2013/11/27/how-to-access-session-variables-using-javascript-in-asp-net/comment-page-1/#comment-294​


Below is my javascriptcode Code.When i am using the above links code in my javascript code if condition i am getting an error

Error:-The Controls collection cannot be modified because the control contains code blocks (i.e. ).


JavaScript
<script type="text/javascript" >

function showorhide(id) {
    if (document.getElementById(id).style.display == "none") {
    document.getElementById(id).style.display = "block";
    var idA = id;
    if (idA == "workdiv3") {
    //Here i want to Assign the session["Diplay"]="Yes"
    }
    }
else {
    document.getElementById(id).style.display = "none";
    var idA = id;
    if (idA == "workdiv3") {
//Here i want to Assign the session["Diplay"]="No"
    }
}
}
</script>
Posted
Updated 24-Feb-14 19:44pm
v4
Comments
JoCodes 24-Feb-14 23:34pm    
I tested your Sample link code , it works fine. Can you please post the Code which you tried?
ntitish 25-Feb-14 1:35am    
Sir i update my javascript code......in my question

1 solution

XML
var id = "10";
'<%Session["x"] = "' + id +'"; %>' ;

alert('<%=Session["x"] %>');
 
Share this answer
 
Comments
ntitish 25-Feb-14 2:07am    
If i am placing this code in my if condition the following error is coming
Error:-The Controls collection cannot be modified because the control contains code blocks (i.e. ).
Did i missed any thing.
k07 25-Feb-14 2:52am    
hi..

From Where you passing this id . pls show that code
ntitish 25-Feb-14 4:27am    
sir r u asking about javascript code ...............

<script type="text/javascript" >



function showorhide(id) {
if (document.getElementById(id).style.display == "none") {
document.getElementById(id).style.display = "block";
var idA = id;
if (idA == "workdiv3") {
var id = "10";
'<%Session["x"] = "' + id + '"; %>';

alert('<%=Session["x"] %>');
}
}
else {
document.getElementById(id).style.display = "none";
var idA = id;
if (idA == "workdiv3") {
var id = "11";
'<%Session["x"] = "' + id + '"; %>';

alert('<%=Session["x"] %>');
}
}
}
</script>
k07 25-Feb-14 6:20am    
no....from where u call this JS fun ..in onclick=showorhide() ??
pls show that code..
ntitish 25-Feb-14 6:23am    
sir insted of this session code i simply kept alert it is working 5n.....but there is problem in session tags because when i searched my error i found this link

http://www.aspdotnet-suresh.com/2011/12/aspnet-controls-collection-cannot-be.html

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900