
Herman Gouw
Top achievements
Rank 2
Herman Gouw
asked on 04 Apr 2011, 08:02 AM
Hi,
In my current project, I am using Visual Studio 2008, .NET Framework 3.5 and Telerik 2011 Q1.
On one of the web pages which use a common master page, I need to retrieve the value of a Session whose is set by the code behind.
<asp:Content ID="Content1" ContentPlaceHolderID="Main" runat="server">
<script type="text/javascript">
function showConfirm() {
var exist = '<%= Session("SubscriptionsExist")%>';
...
}
</script>
...
</asp:Content>
I got the following error message
Compiler Error Message: CS0103: The name 'Session' does not exist in the current context
If I used the following instead
var exist = '<%= Session("SubscriptionsExist")%>';
I got the following error message
Compiler Error Message: CS1955: Non-invocable member 'System.Web.HttpContext.Session' cannot be used like a method.
Can you please help me?
Regards,
Herman
In my current project, I am using Visual Studio 2008, .NET Framework 3.5 and Telerik 2011 Q1.
On one of the web pages which use a common master page, I need to retrieve the value of a Session whose is set by the code behind.
<asp:Content ID="Content1" ContentPlaceHolderID="Main" runat="server">
<script type="text/javascript">
function showConfirm() {
var exist = '<%= Session("SubscriptionsExist")%>';
...
}
</script>
...
</asp:Content>
I got the following error message
Compiler Error Message: CS0103: The name 'Session' does not exist in the current context
If I used the following instead
var exist = '<%= Session("SubscriptionsExist")%>';
I got the following error message
Compiler Error Message: CS1955: Non-invocable member 'System.Web.HttpContext.Session' cannot be used like a method.
Can you please help me?
Regards,
Herman
6 Answers, 1 is accepted
0

Shinu
Top achievements
Rank 2
answered on 04 Apr 2011, 08:33 AM
Hello Herman,
I was not able to create the same error and one suggestion is to save the session variable in a Hidden Field and access it.
Thanks,
Shinu.
I was not able to create the same error and one suggestion is to save the session variable in a Hidden Field and access it.
//Code Behind
session[
"name"
]=
"well"
;
hiddenctrl.value=session[
"name"
].ToString();
client-side:
javascript:
var sessionvalue= document.getElementById(
'hiddenctrl'
).value;
Thanks,
Shinu.
0

Herman Gouw
Top achievements
Rank 2
answered on 04 Apr 2011, 08:47 AM
Thanks for the prompt reply.
Is it possible to read the Session value directly from JavaScript without using a hidden control?
The problem with a hidden control is that it is possible to check the value by viewing the source from the browser.
Regards,
Herman
Is it possible to read the Session value directly from JavaScript without using a hidden control?
The problem with a hidden control is that it is possible to check the value by viewing the source from the browser.
Regards,
Herman
0

Shinu
Top achievements
Rank 2
answered on 05 Apr 2011, 09:19 AM
Hello Herman,
I have made some changes in your code. Please give a try with this.
Javascript:
Thanks,
Shinu.
I have made some changes in your code. Please give a try with this.
Javascript:
<script type=
"text/javascript"
>
function
accessSession()
{
var
mySessionVar =
'<%=Session["name"]%>'
;
//make sure that you have defined the session variable
alert(mySessionVar);
}
</script>
Thanks,
Shinu.
0

Herman Gouw
Top achievements
Rank 2
answered on 06 May 2011, 06:05 AM
Hi Shinu,
I have modified the code to the sample that you gave me.
I have also initialized the Session variable to a value in Global.asax.cs as follows:
protected void Session_Start(object sender, EventArgs e)
{
Session["name"] = true;
}
However I got the following error message:
Description:
An unhandled exception occurred during the execution of the current web
request. Please review the stack trace for more information about the error and
where it originated in the code.
Exception Details: System.Web.HttpException: The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).
Regards,
Herman
I have modified the code to the sample that you gave me.
I have also initialized the Session variable to a value in Global.asax.cs as follows:
protected void Session_Start(object sender, EventArgs e)
{
Session["name"] = true;
}
The Controls collection cannot be modified because the control contains
code blocks (i.e. <% ... %>).
Description:
An unhandled exception occurred during the execution of the current web
request. Please review the stack trace for more information about the error and
where it originated in the code. Exception Details: System.Web.HttpException: The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).
Regards,
Herman
0
You cannot send a server value (in this case - a session value) to the client and use that in javascript without sending it somewhere in the server response. You need to send that value in your rendered HTML, which is effectively the same as using a hidden field.
Veli
the Telerik team
Veli
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0

Bojjaiah
Top achievements
Rank 1
answered on 13 Jul 2011, 06:54 AM
Hi thanks for your post sejjestion
now working fine
tahnks alot!
now working fine
tahnks alot!