Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hello:

I have a class where I�m using session variables, notwithstanding when I compile Project it�s sending me this error: �Name �session� doesn�t exist in class or namespace �WUC_CreDes.Class1��.

Does it mean that it is not permitted to me using session variables into a class?

This is my code:

 

using System;

using System.Collections;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Web;

using System.Web.SessionState;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.HtmlControls;

 

namespace WUC_CreDes

{

public class Class1

{

public static bool No_PostBack()

{

Session["par1"] = "";

return false;

}

}

}

 

Thank you in advance for your help.

 

A.L.

  • Moderators
Posted

You need to import system.Web, then do this in your constructor; I'm sure you can figure out from here.

 

private string _sessionId;

private HttpContext _httpContext = null;

public class1(string currentSessionID)

{

_httpContext = HttpContext.Current;

_sessionId= currentSessionID;

}

 

I would make this a base class to handle all state, it comes in handy when you have multiple developers.

Visit...Bassic Software

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...