473,398 Members | 2,165 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

request is not available in this context

Hi,

I created a class(AAA) which derives from System.Web.UI.Page.
In the new class (AAA) I created some private variables and I
initialize the variables from the property "Request".
For some reason, I get an exception in the initialization -
"request is not available in this context" .
I tried the same with the property "Session" and didn't have any
problems.

Mayby someone has any idea ??

Thanks.
Ruthie.

Feb 20 '07 #1
2 12568
Good morning,

I'm quessing, you are initializing variables like this:

public class MyPageClass : System.Web.UI.Page
{
private string myVariable = Request.QueryString["blabla"];
....
}
which is not allowed because initialization takes place before HttpRequest
instance is created. If you use any of the page core objects like Session,
Request you can initialize variables (starting from) Init event:

public class MyPageClass : System.Web.UI.Page
{
private string myVariable;

protected void Page_Init(object sender, EventArgs e)
{
this.myVariable = Request.QueryString["blabla"];
}
}

or use 'lazy' initialization in conjunction with a property:

public class MyPageClass : System.Web.UI.Page
{
private string myVariable;
protected /* or public */ string MyVariable
{
get
{
if (this.myVariable == null)
{
this.myVariable = Request.QueryString["blabla"];
if (this.myVariable == null)
this.myVariable = String.Empty;
}
return this.myVariable;
}
}

}

Then use the property instead of private variable:

MyExtraFunction(MyVariable);
Hope this helps
--
Milosz
"ru******@walla.co.il" wrote:
Hi,

I created a class(AAA) which derives from System.Web.UI.Page.
In the new class (AAA) I created some private variables and I
initialize the variables from the property "Request".
For some reason, I get an exception in the initialization -
"request is not available in this context" .
I tried the same with the property "Session" and didn't have any
problems.

Mayby someone has any idea ??

Thanks.
Ruthie.

Feb 20 '07 #2
On Feb 20, 1:16 pm, Milosz Skalecki [MCAD] <mily...@DONTLIKESPAMwp.pl>
wrote:
Good morning,

I'm quessing, you are initializing variables like this:

public class MyPageClass : System.Web.UI.Page
{
private string myVariable = Request.QueryString["blabla"];
...}

which is not allowed because initialization takes place before HttpRequest
instance is created. If you use any of the page core objects like Session,
Request you can initialize variables (starting from) Init event:

public class MyPageClass : System.Web.UI.Page
{
private string myVariable;

protected void Page_Init(object sender, EventArgs e)
{
this.myVariable = Request.QueryString["blabla"];
}

}

or use 'lazy' initialization in conjunction with a property:

public class MyPageClass : System.Web.UI.Page
{
private string myVariable;
protected /* or public */ string MyVariable
{
get
{
if (this.myVariable == null)
{
this.myVariable = Request.QueryString["blabla"];
if (this.myVariable == null)
this.myVariable = String.Empty;
}
return this.myVariable;
}
}

}

Then use the property instead of private variable:

MyExtraFunction(MyVariable);

Hope this helps
--
Milosz

"ruthi...@walla.co.il" wrote:
Hi,
I created a class(AAA) which derives from System.Web.UI.Page.
In the new class (AAA) I created some private variables and I
initialize the variables from the property "Request".
For some reason, I get an exception in the initialization -
"request is not available in this context" .
I tried the same with the property "Session" and didn't have any
problems.
Mayby someone has any idea ??
Thanks.
Ruthie.- Hide quoted text -

- Show quoted text -
Hi Milosz,

Thanks so much for your excellent detailed explanation!!!
Problem is solved.

Best Regards,
Ruthie.

Feb 20 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Sascha Kuhl | last post by:
I'm working on a piece of code that sets a cookie, depending on the some Session State values in the PreRequestHandlerExecute event of my App. The code works on my development machine (Windows...
5
by: Pepehammer | last post by:
Exception Details: System.Web.HttpException: Response is not available in this context. Source Error: Line 16: '---------- // SUB : WriteString Line 17: Public Sub WriteString(SayItNow as...
1
by: rao | last post by:
Hi I am generating unique xml files and deleting them in page_unload event. Application responds properly in normal conditions. When I keep clicking on url that invoke the page several times the...
0
by: Rahul_Borade | last post by:
Hi, I have one project which is made in VS 2003 now I have conveted it into Whidbey. The project contais many crystal report files. On all pages, those which contains Crystal report Viewer...
0
by: Blasting Cap | last post by:
I had some old code set to throw an email to me when a user hit an exception. VS 2003 worked fine with the code, VS 2005 when I run it in debug mode pauses over the code each time, and gives me...
0
by: gunjanhshah | last post by:
Hello My system reports the following application event log. The log is due to my web application which is built upon asp.net and sql server 2000 and uses Active directory users to authenticate....
2
by: =?Utf-8?B?QW5keSBD?= | last post by:
Hi, I'm trying to load some XML into a dataset with C# but I have an issue with the schema. I'm using exactly the same code to successfully load other XML. The only difference is in the XML...
3
by: doofy | last post by:
I'm trying to create a custom control which would be a treeview which populates itself with table and field details from a database. I need to be able to call up a form to enter the server/db...
10
BeemerBiker
by: BeemerBiker | last post by:
I get that error message when trying to do a "Response.write()". I undoubtedly set up my classes wrong. My workaround is to put the offending code in each codebehind page. I would like to put the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.