473,407 Members | 2,546 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,407 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 1873
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.