• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2430
  • Last Modified:

System.Web.HttpException: Request is not available in this context

I want to make a couple variables global within my page so that I do not have to keep redefining them in each method.  I tried moving these out of Page_Load

    Dim StudentID As Integer = Request.QueryString("syStudentID")
    Dim LeadID As Integer = GetmkLeadID(StudentID)

I get this: System.Web.HttpException: Request is not available in this context
  • 3
  • 2
1 Solution
Jai STech ArchCommented:
if you want them as global dont declare them in the page_load

declare them in your form decaration part and use them in the page_load
StudentId = Request.QueryString("sdfd")

Query String can be accessed in page_load
Make sure you have declared the variable between the partial class declaration and page load function

Partial Class description
    Inherits System.Web.UI.Page
    Dim StudentID As Integer
    Dim LeadID As Integer
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    End Sub
dba123Author Commented:
I had them declared in the Page_Load initially....but that didn't guarantee that all methods could see it.
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Jai STech ArchCommented:
why was the point not split...it was me who answered the question first...
dba123Author Commented:
Because the answer is this.

1) Declare the variables but don't initialize them in the class, before the Page_Load
2) Initialize the variable in the Page_Load only

I had to separate the two out.  Your sentences didn't suggest this or were at least not clear to me.
Jai STech ArchCommented:
thnk you so much...i will post this to the community advisor and will ask for his suggestion...
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now