need help on scope of a function for intellisence

G

Guest

Hi,

I am writing a webpage in C#. Visual Studio .NET.

the following code does not provide me with intellisence on the context,
session, and page.cache.

When I put the large if...then statment from the GetJSHyperlinksString()
function
into the private void on page load event the intellisence works fine.

I pretty sure I'm not declaring the function properly and my scope is wrong.
the function is : public static string GetJSHyperlinksString()

I also get object reference is required for nonstatic field and a property
where a class was expected errors at compile on the context, session, and
page.cache statements.

Please advise.

code is:

public class leftnav : System.Web.UI.Page
{
public const string CACHE_NAV_DATA = "NavData";
public const string SESSION_NAV_DATA = "UserSessionNavData";

protected System.Web.UI.HtmlControls.HtmlForm Form1;

private void Page_Load(object sender, System.EventArgs e)

{
RegisterLinkButtonScript();
}

public static string GetJSHyperlinksString()
{
//this function will determine the hyperlinks available to the logged
//in user by reading the database. Default hyperlinks are constructed
//for those who are not logged in.

object objsession;
string JSHyperlinksString = string.Empty;

//check to see if the hyperlinks already exist.
//this javascript code is parsed by the worker thread into an
//unmanaged client side code whenever it is retrieved by the
//page.cache.get method

if(Context.User.Identity.IsAuthenticated)
{
objsession = Session[SESSION_NAV_DATA];
}
else
{
objsession = Page.Cache[CACHE_NAV_DATA];
}
 
I

Ignacio Machin \( .NET/ C# MVP \)

hi,

put three /// in the line above the function declaration, the IDE will
expand it with the structure needed.

cheers,
 
G

Guest

public const string CACHE_NAV_DATA = "NavData";
public const string SESSION_NAV_DATA = "UserSessionNavData";

please replace :


public string CACHE_NAV_DATA = "NavData";
public string SESSION_NAV_DATA = "UserSessionNavData";
 
G

Guest

this does'nt seem to help, it causes more errors to occur in the build.
I also don't think this is related to my problem.

thanks

Keko said:
public const string CACHE_NAV_DATA = "NavData";
public const string SESSION_NAV_DATA = "UserSessionNavData";

please replace :


public string CACHE_NAV_DATA = "NavData";
public string SESSION_NAV_DATA = "UserSessionNavData";



Chris said:
Hi,

I am writing a webpage in C#. Visual Studio .NET.

the following code does not provide me with intellisence on the context,
session, and page.cache.

When I put the large if...then statment from the GetJSHyperlinksString()
function
into the private void on page load event the intellisence works fine.

I pretty sure I'm not declaring the function properly and my scope is wrong.
the function is : public static string GetJSHyperlinksString()

I also get object reference is required for nonstatic field and a property
where a class was expected errors at compile on the context, session, and
page.cache statements.

Please advise.

code is:

public class leftnav : System.Web.UI.Page
{
public const string CACHE_NAV_DATA = "NavData";
public const string SESSION_NAV_DATA = "UserSessionNavData";

protected System.Web.UI.HtmlControls.HtmlForm Form1;

private void Page_Load(object sender, System.EventArgs e)

{
RegisterLinkButtonScript();
}

public static string GetJSHyperlinksString()
{
//this function will determine the hyperlinks available to the logged
//in user by reading the database. Default hyperlinks are constructed
//for those who are not logged in.

object objsession;
string JSHyperlinksString = string.Empty;

//check to see if the hyperlinks already exist.
//this javascript code is parsed by the worker thread into an
//unmanaged client side code whenever it is retrieved by the
//page.cache.get method

if(Context.User.Identity.IsAuthenticated)
{
objsession = Session[SESSION_NAV_DATA];
}
else
{
objsession = Page.Cache[CACHE_NAV_DATA];
}
 
G

Guest

I added the /// to just before the function starts, it created my summary and
tags.
However I still have same problem.

How does adding comments to the function change the scope and availablity
of the assemblies to the function?
curious.

Ignacio Machin ( .NET/ C# MVP ) said:
hi,

put three /// in the line above the function declaration, the IDE will
expand it with the structure needed.

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation


Chris said:
Hi,

I am writing a webpage in C#. Visual Studio .NET.

the following code does not provide me with intellisence on the context,
session, and page.cache.

When I put the large if...then statment from the GetJSHyperlinksString()
function
into the private void on page load event the intellisence works fine.

I pretty sure I'm not declaring the function properly and my scope is
wrong.
the function is : public static string GetJSHyperlinksString()

I also get object reference is required for nonstatic field and a property
where a class was expected errors at compile on the context, session, and
page.cache statements.

Please advise.

code is:

public class leftnav : System.Web.UI.Page
{
public const string CACHE_NAV_DATA = "NavData";
public const string SESSION_NAV_DATA = "UserSessionNavData";

protected System.Web.UI.HtmlControls.HtmlForm Form1;

private void Page_Load(object sender, System.EventArgs e)

{
RegisterLinkButtonScript();
}

public static string GetJSHyperlinksString()
{
//this function will determine the hyperlinks available to the logged
//in user by reading the database. Default hyperlinks are constructed
//for those who are not logged in.

object objsession;
string JSHyperlinksString = string.Empty;

//check to see if the hyperlinks already exist.
//this javascript code is parsed by the worker thread into an
//unmanaged client side code whenever it is retrieved by the
//page.cache.get method

if(Context.User.Identity.IsAuthenticated)
{
objsession = Session[SESSION_NAV_DATA];
}
else
{
objsession = Page.Cache[CACHE_NAV_DATA];
}
 
C

Christof Nordiek

Hi Chris,

why the GetJSHyperlinksString() is static?

I suppose you're trying to access instance members inside a static member.
That's not possible.

Christof
 
G

Guest

Hi Christof,

I just finished reading about that in the documentation.

i put static because I want my function to return a value without creating
an instance of itself, basically a function like found in an inception
filter pattern to
perform a generic process.

I removed the static and it works fine.

thanks
Christof Nordiek said:
Hi Chris,

why the GetJSHyperlinksString() is static?

I suppose you're trying to access instance members inside a static member.
That's not possible.

Christof

Chris said:
Hi,

I am writing a webpage in C#. Visual Studio .NET.

the following code does not provide me with intellisence on the context,
session, and page.cache.

When I put the large if...then statment from the GetJSHyperlinksString()
function
into the private void on page load event the intellisence works fine.

I pretty sure I'm not declaring the function properly and my scope is
wrong.
the function is : public static string GetJSHyperlinksString()

I also get object reference is required for nonstatic field and a property
where a class was expected errors at compile on the context, session, and
page.cache statements.

Please advise.

code is:

public class leftnav : System.Web.UI.Page
{
public const string CACHE_NAV_DATA = "NavData";
public const string SESSION_NAV_DATA = "UserSessionNavData";

protected System.Web.UI.HtmlControls.HtmlForm Form1;

private void Page_Load(object sender, System.EventArgs e)

{
RegisterLinkButtonScript();
}

public static string GetJSHyperlinksString()
{
//this function will determine the hyperlinks available to the logged
//in user by reading the database. Default hyperlinks are constructed
//for those who are not logged in.

object objsession;
string JSHyperlinksString = string.Empty;

//check to see if the hyperlinks already exist.
//this javascript code is parsed by the worker thread into an
//unmanaged client side code whenever it is retrieved by the
//page.cache.get method

if(Context.User.Identity.IsAuthenticated)
{
objsession = Session[SESSION_NAV_DATA];
}
else
{
objsession = Page.Cache[CACHE_NAV_DATA];
}
 
J

Jon Skeet [C# MVP]

Keko said:
public const string CACHE_NAV_DATA = "NavData";
public const string SESSION_NAV_DATA = "UserSessionNavData";

please replace :


public string CACHE_NAV_DATA = "NavData";
public string SESSION_NAV_DATA = "UserSessionNavData";

Why? They're constant strings, and they don't need to be writable as
far as I can see...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top