Link to home
Start Free TrialLog in
Avatar of tentavarious
tentavarious

asked on

Can't set a session variable with ajax asp.net 1.1???

Experts I am trying to set a session variable using ajax and I keep getting this error:
"Session State can only be used when the enabled session sate is set to true either in configuration file or page directive. "

 I have never had this problem before setting session's its just when I try to set a session with an ajax function

 <Ajax.JavascriptMethod()> _
       Public Function setweekly(sval as string)
try
       Session("statename") = sval
catch ex as exception
sval = ex.message
end try
return sval
    End Function
Avatar of tentavarious
tentavarious

ASKER

I tried this HttpContext.current.session("statename") = sval
But then I get this error Object not set to an instance of an object
Avatar of Bob Learned
Are you talking about the Microsoft AJAX framework?  Or AJAXPro?

Bob
I believe its the microsoft ajax framework, but I am not real sure, where do i check?
Look at the project references, and see what DLL is being referenced for the AJAX implementation.

Bob
It just says AJAX
Does the \bin folder have any DLL files that are related to AJAX?

Bob
Just the Ajax.dll file it does say below the file name Ajax.net Wrapper.  That is all I have in that folder.
Ok, so now it is sounding like Ajax.NET Pro:

http://ajaxpro.schwarz-interactive.de/

Session State handling with Ajax.NET
Now, we you can access your session variables, there was a small bug.

On the server the C# method looks like following code:

[AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
public void Test5(string value)
{
  System.Web.HttpContext.Current.Session["example"] = value;
}

[AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.Read)]
public string Test6()
{
  if(System.Web.HttpContext.Current.Session["example"] != null)
    return (string)System.Web.HttpContext.Current.Session["example"];

  return "First set the value...";
}

Bob
Not sure what is going on but I keep getting this error: Object not set to an instance of an object when I try your code.  I am using vb.net so I made a small change:

      Try
            System.Web.HttpContext.Current.Session("example") = sval
        Catch ex As Exception
            Dim e As String
            e = ex.Message
        End Try

Do i need to download an update to ajax?
Ok, I dont think I have ajax pro my attribute is different from yours

 <Ajax.JavascriptMethod()> _
     Public Function getstation2(nameval as string)
        'Gets the current pace
        Dim sval As String
             Try
            System.Web.HttpContext.Current.Session("example") = sval
        Catch ex As Exception
            Dim e As String
            e = ex.Message
        End Try
        Return sval
    End Function

I tried using this attribute tag instead
 <Ajax.JavascriptXmlHttp()> _

but it doesnt like that I get an error.
   
That is why it is important to understand what version of AJAX that you are using.  Without specific information, it will be very difficult to provide any guidance.

Bob

Alls I know is I downloaded a free version that works with asp.net 1.1, where can I download the professional version that works with asp.net 1.1?  I was doing some searching and my ajax dll file name is not the same as the professional file name, so I have no idea what version I could be using.
ASKER CERTIFIED SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial