| | |||||||
|
Welcome to the YD Scuba forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions, articles and access our other FREE features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact contact support. |
| Technology: Discuss C# .NET - Session variables inside an abstract class in the Non-Diving Related Forums forums: OK, so am not sure if this is the problem, but I have an abstract class in my web application ... |
| | LinkBack | Thread Tools | Display Modes |
| ||||
| Hmmmmm. The only reason I can't normally access 'session' (pub.beer.session) is because 'wife' (front.door.blocking) demands all my CPU time. |
| ||||
| what error do you get when you compile, i would think that due to the class being static it will not be able to access the session info, can you not change the interface of the static methods and pass the objects to the static class from the calls, or am i wide of the mark here. Ron |
| ||||
| Quote:
For each reference to the Session["key"], I get "The name 'Session' does not exist in the class or namespace 'KP2.Utilities'" I have added a using to System.Web, and my current solution is to pass all the session variables as parameters to the static procedure, but I was just hoping to do all the repetion in the routine rather than just pass in all the info each time. Currently, my call and procedure looks like this: Code: vWriter = Utilities.WriteReportTitles( "Market Analysis", strCodesTitle, vTitles1, vTitles2 );
public static StreamWriter WriteReportTitles( string aReportTitle, string aCodesTitle, string aTitles1, string aTitles2 ) {
MemoryStream vStream = new MemoryStream();
StreamWriter vWriter = new StreamWriter( vStream );
// initialise string to show report title
vWriter.WriteLine( aReportTitle );
// add blank line
string pReportText = string.Empty;
vWriter.WriteLine( pReportText );
// add other elements of title one by one
pReportText = "Base Date: " + Session["strDisplayEffDate"].ToString();
vWriter.WriteLine( pReportText );
pReportText = "Market Cut: " + Session["strCompanyGroupDescription"].ToString();
vWriter.WriteLine( pReportText );
pReportText = "Jobs: " + aCodesTitle;
vWriter.WriteLine( pReportText );
pReportText = "Locations/regions: " + Session["strRegionsTitle"].ToString();
vWriter.WriteLine( pReportText );
pReportText = "Regional Pay Factor: " + Session["RegionalPayFactor"].ToString() + "%";
vWriter.WriteLine( pReportText );
pReportText = "Aging Factor: " + Session["AgingFactor"].ToString() + "%";
vWriter.WriteLine( pReportText );
pReportText = "Run on: " + DateTime.Now.ToLongDateString();
vWriter.WriteLine( pReportText );
// add first line to column titles
vWriter.WriteLine( aTitles1 );
// add second line of column titles
vWriter.WriteLine( aTitles2 );
// return stream
return( vWriter );
}
An object reference is required for the nonstatic field, method, or property 'KP2.Utilities.WriteReportTitles(string, string, string, string)' I hope this makes more sense Martin Last edited by MartinS : 23-08-06 at 09:59 AM. |
| ||||
| Quote:
|
| ||||
| as this is asp.net why not add Trace="true" to the end of the <%@ Page line (HTML) this will allow you to see the all the session values for the page other that than that i cant see an answer without all the code, but one place i will direct you to is the GotDotNet: The Microsoft .NET Framework Community post the question or search the ASP.NET forum. Ron |
| ||||
| Ron I have resolved it by adding a new class to do the job, and using some get properties to read the session variables where required. I think the problem is that the class is not an asp class, just a standard class, i.e. it does not reside behind a ASP web page. Thanks anyway for your time, and also the link. Thanks again Martin |
| Thread Tools | |
| Display Modes | |
| |
| | ||