472,992 Members | 3,200 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Public varaible QueryString issue

VK
Folks,

An aspx page has some querystring variables in the URL.

In the code beind file, I tried requesting these variables and setting
as public variables, so it is not specific to a sub.

Public instance_id As Decimal = Request.QueryString("i_id")

This is defined right above:Private Sub Page_Load

It doesn't work - is something missing??

Thanks.

*** Sent via Developersdex http://www.developersdex.com ***
Jul 22 '05 #1
11 1855
Does it error or simply not set the value?
"VK" wrote:
Folks,

An aspx page has some querystring variables in the URL.

In the code beind file, I tried requesting these variables and setting
as public variables, so it is not specific to a sub.

Public instance_id As Decimal = Request.QueryString("i_id")

This is defined right above:Private Sub Page_Load

It doesn't work - is something missing??

Thanks.

*** Sent via Developersdex http://www.developersdex.com ***

Jul 22 '05 #2
Why not set the variable in the Load or Init events?

"VK" <vk@vk.com> wrote in message
news:OG**************@tk2msftngp13.phx.gbl...
Folks,

An aspx page has some querystring variables in the URL.

In the code beind file, I tried requesting these variables and setting
as public variables, so it is not specific to a sub.

Public instance_id As Decimal = Request.QueryString("i_id")

This is defined right above:Private Sub Page_Load

It doesn't work - is something missing??

Thanks.

*** Sent via Developersdex http://www.developersdex.com ***

Jul 22 '05 #3
VK
The error message:
Request is not available in this context
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

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

Source Error:
Line 40: Public myConn As SqlConnection = New
SqlConnection(ConfigurationSettings.AppSettings("O nlineToolkitv2"))
Line 41: Public tool_id As Decimal = 1
Line 42: Public instance_id As Integer = Request.QueryString("i_id")
Line 43: Public number_of_questions As Integer

- I can't use it in Load since it cannot be used in other subs or
functions, its scope would exist with in Load only.

thanks.

*** Sent via Developersdex http://www.developersdex.com ***
Jul 22 '05 #4

Hard to tell from the chunks of code you posted, but it seems to me like you
are NOT putting this declarations inside the Page_Load Event. It looks to me
like you are placing them as classwide scope variables and trying to
initialize them to a value, which would explain why the request object is not
available.

Place the variable definitions classwide scope and initalize the values in
the page_load event.

Good luck!

--
Juan Romero
-----------------------------------------
The successful person has the habit of doing the things failures don't like
to do.
E.M. Gray
"VK" wrote:
The error message:
Request is not available in this context
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

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

Source Error:
Line 40: Public myConn As SqlConnection = New
SqlConnection(ConfigurationSettings.AppSettings("O nlineToolkitv2"))
Line 41: Public tool_id As Decimal = 1
Line 42: Public instance_id As Integer = Request.QueryString("i_id")
Line 43: Public number_of_questions As Integer

- I can't use it in Load since it cannot be used in other subs or
functions, its scope would exist with in Load only.

thanks.

*** Sent via Developersdex http://www.developersdex.com ***

Jul 22 '05 #5
VK
I set this:
Public instance_id As Integer = Request.QueryString("i_id")

right above Page_load, so that this variable could be used in all subs.

It fails near the request.querystring.

Will this not work?

Thanks

*** Sent via Developersdex http://www.developersdex.com ***
Jul 22 '05 #6
The Request object may not have been fully initialized when the class is
constructed. You should only set variables like this in the Init or Load
events. If your design is requiring that you do it this way, you may need
to reevaluate your design. There is a reason that ASP.NET defines a life
cycle for the pages (Init-->LoadViewState-->Load-->(control
events)-->SaveViewState-->PreRender-->Unload). At each stage, there is
something new available to your system.

"VK" <vk@vk.com> wrote in message
news:uE**************@tk2msftngp13.phx.gbl...
I set this:
Public instance_id As Integer = Request.QueryString("i_id")

right above Page_load, so that this variable could be used in all subs.

It fails near the request.querystring.

Will this not work?

Thanks

*** Sent via Developersdex http://www.developersdex.com ***

Jul 22 '05 #7
No. It will not.

Just because you want the variable to be available to all subs does not mean
that you have to INITIALIZE it there.

Leave the variable where it is but initialize the value in the page_load
event.

E.G.:

Public instance_id As Integer

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
instance_id = request.querystring("i_id")
End If
End Sub

Also, keep in mind that your variable will not retain its value across
postbacks unless you store in a persistant medium such as the session or the
viewstate.

Good luck!
--
Juan Romero
-----------------------------------------
The successful person has the habit of doing the things failures don't like
to do.
E.M. Gray
"VK" wrote:
I set this:
Public instance_id As Integer = Request.QueryString("i_id")

right above Page_load, so that this variable could be used in all subs.

It fails near the request.querystring.

Will this not work?

Thanks

*** Sent via Developersdex http://www.developersdex.com ***

Jul 22 '05 #8
VK
Actually it would maintain its value by defining the following way.

=====

Public instance_id As Integer

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
instance_id = request.querystring("i_id")
If Not IsPostBack Then
' code
End If
End Sub

====

It is working!

thanks. Vani

*** Sent via Developersdex http://www.developersdex.com ***
Jul 22 '05 #9
Hi,

I am glad to hear it's working. Are you sure it mantains its value across
postbacks?... I don't think so, but I may be wrong. Check it out.

Good luck!
--
Juan Romero
-----------------------------------------
The successful person has the habit of doing the things failures don't like
to do.
E.M. Gray
"VK" wrote:
Actually it would maintain its value by defining the following way.

=====

Public instance_id As Integer

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
instance_id = request.querystring("i_id")
If Not IsPostBack Then
' code
End If
End Sub

====

It is working!

thanks. Vani

*** Sent via Developersdex http://www.developersdex.com ***

Jul 22 '05 #10
VK
I set this:
Public instance_id As Integer = Request.QueryString("i_id")

right above Page_load, so that this variable could be used in all subs.

It fails near the request.querystring.

Will this not work?

Thanks

*** Sent via Developersdex http://www.developersdex.com ***
Nov 22 '05 #11
The Request object may not have been fully initialized when the class is
constructed. You should only set variables like this in the Init or Load
events. If your design is requiring that you do it this way, you may need
to reevaluate your design. There is a reason that ASP.NET defines a life
cycle for the pages (Init-->LoadViewState-->Load-->(control
events)-->SaveViewState-->PreRender-->Unload). At each stage, there is
something new available to your system.

"VK" <vk@vk.com> wrote in message
news:uE**************@tk2msftngp13.phx.gbl...
I set this:
Public instance_id As Integer = Request.QueryString("i_id")

right above Page_load, so that this variable could be used in all subs.

It fails near the request.querystring.

Will this not work?

Thanks

*** Sent via Developersdex http://www.developersdex.com ***

Nov 22 '05 #12

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

Similar topics

2
by: braindead | last post by:
Hi All Is 1. dopage.asp?<% =SessionID=value_here%> is different tha 2. dopage.asp?<%=SessionID=value_here%> ?? Please note that there is a space between the asp tags and the = sign in the...
0
by: scott | last post by:
Below, I'm trying to remove the querystring name& value of "catID=12". I mananged to isolate the RESULTS part, but I need to be able to strip the querystring name and it's value, no matter if the...
12
by: Alex | last post by:
I have a question about determining if one QueryString keys exists. The idea is, if this key exists, than its presence is enough to indicate that its value is true. For example ... ...
6
by: VK | last post by:
Folks, An aspx page has some querystring variables in the URL. In the code beind file, I tried requesting these variables and setting as public variables, so it is not specific to a sub. ...
2
by: Darrel | last post by:
I'm working on an app where the ASPX pages aren't precompiled with the class.vb files I'm. This is so people can add their own ASPX pages down the road to the app (the .aspx pages become...
7
by: fox | last post by:
Hi, Lacking javascript knowledge, I just realized why my project has a bug. I am using ASP to loop through a set of records while it creates URLs with a querystring that has a single value pair....
10
by: Phillip Vong | last post by:
Newbie learning in VB.NET 2. I'm creating a simple ASP.NET 2 page and I pulling a querystring from a link and I want to use this querystring over and over again through out the page. Example....
3
by: Simon Gare | last post by:
Hi All, I have a querystring that contains the + sign as a separator, I need to read these values individually in a select statement, for example. &text=Single+205 where single is the type...
5
by: magix8 | last post by:
Hi, I have form GET method, example: index.asp?Type=1&Type=3&Type=4&.... So, I have something like this at the receiver side to retrieve multiple Type value and insert into tables.
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
3
SueHopson
by: SueHopson | last post by:
Hi All, I'm trying to create a single code (run off a button that calls the Private Sub) for our parts list report that will allow the user to filter by either/both PartVendor and PartType. On...

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.